summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2009-04-02 16:56:04 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-04-02 16:56:04 (GMT)
commit87d9469e428296a2fb8d0f266900cdfe816eaf0a (patch)
treef8219cadd57c0013f619030b44068adc009e2058 /tools
parentceb253c234f840f7aeec10fa4450e840c6b242f4 (diff)
parent7c09fda559760b8488d3130a5932fee04b2f6979 (diff)
downloadQt-87d9469e428296a2fb8d0f266900cdfe816eaf0a.zip
Qt-87d9469e428296a2fb8d0f266900cdfe816eaf0a.tar.gz
Qt-87d9469e428296a2fb8d0f266900cdfe816eaf0a.tar.bz2
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts: tools/linguist/shared/profileevaluator.cpp
Diffstat (limited to 'tools')
-rw-r--r--tools/assistant/tools/assistant/contentwindow.cpp21
-rw-r--r--tools/assistant/tools/assistant/contentwindow.h2
-rw-r--r--tools/assistant/tools/assistant/helpviewer.cpp59
-rw-r--r--tools/assistant/tools/assistant/helpviewer.h1
-rw-r--r--tools/assistant/tools/assistant/indexwindow.cpp13
-rw-r--r--tools/linguist/lconvert/main.cpp2
-rw-r--r--tools/linguist/linguist/messagemodel.cpp10
-rw-r--r--tools/linguist/lrelease/main.cpp15
-rw-r--r--tools/linguist/lupdate/main.cpp1
-rw-r--r--tools/linguist/shared/profileevaluator.cpp14
-rw-r--r--tools/linguist/shared/qm.cpp1
-rw-r--r--tools/linguist/shared/translator.cpp58
-rw-r--r--tools/linguist/shared/translator.h5
-rw-r--r--tools/linguist/shared/translatormessage.h26
-rw-r--r--tools/linguist/shared/ts.cpp6
15 files changed, 171 insertions, 63 deletions
diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp
index 24e7ca9..89060bd 100644
--- a/tools/assistant/tools/assistant/contentwindow.cpp
+++ b/tools/assistant/tools/assistant/contentwindow.cpp
@@ -132,7 +132,7 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e)
qobject_cast<QHelpContentModel*>(m_contentWidget->model());
if (contentModel) {
QHelpContentItem *itm = contentModel->contentItemAt(index);
- if (itm)
+ if (itm && !isPdfFile(itm))
CentralWidget::instance()->setSourceInNewTab(itm->url());
}
}
@@ -146,16 +146,19 @@ void ContentWindow::showContextMenu(const QPoint &pos)
if (!m_contentWidget->indexAt(pos).isValid())
return;
- QMenu menu;
- QAction *curTab = menu.addAction(tr("Open Link"));
- QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
- menu.move(m_contentWidget->mapToGlobal(pos));
-
QHelpContentModel *contentModel =
qobject_cast<QHelpContentModel*>(m_contentWidget->model());
QHelpContentItem *itm =
contentModel->contentItemAt(m_contentWidget->currentIndex());
+ QMenu menu;
+ QAction *curTab = menu.addAction(tr("Open Link"));
+ QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
+ if (isPdfFile(itm))
+ newTab->setEnabled(false);
+
+ menu.move(m_contentWidget->mapToGlobal(pos));
+
QAction *action = menu.exec();
if (curTab == action)
emit linkActivated(itm->url());
@@ -175,4 +178,10 @@ void ContentWindow::itemClicked(const QModelIndex &index)
}
}
+bool ContentWindow::isPdfFile(QHelpContentItem *item) const
+{
+ const QString &path = item->url().path();
+ return path.endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive);
+}
+
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/contentwindow.h b/tools/assistant/tools/assistant/contentwindow.h
index ab8f8dd..ddc3e7c 100644
--- a/tools/assistant/tools/assistant/contentwindow.h
+++ b/tools/assistant/tools/assistant/contentwindow.h
@@ -49,6 +49,7 @@
QT_BEGIN_NAMESPACE
class QHelpEngine;
+class QHelpContentItem;
class QHelpContentWidget;
class ContentWindow : public QWidget
@@ -75,6 +76,7 @@ private:
void focusInEvent(QFocusEvent *e);
void keyPressEvent(QKeyEvent *e);
bool eventFilter(QObject *o, QEvent *e);
+ bool isPdfFile(QHelpContentItem *item) const;
QHelpEngine *m_helpEngine;
QHelpContentWidget *m_contentWidget;
diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp
index 6b049e8..f7225fa 100644
--- a/tools/assistant/tools/assistant/helpviewer.cpp
+++ b/tools/assistant/tools/assistant/helpviewer.cpp
@@ -164,6 +164,7 @@ public:
protected:
virtual QWebPage *createWindow(QWebPage::WebWindowType);
+ virtual void triggerAction(WebAction action, bool checked = false);
virtual bool acceptNavigationRequest(QWebFrame *frame,
const QNetworkRequest &request, NavigationType type);
@@ -171,16 +172,30 @@ protected:
private:
CentralWidget *centralWidget;
QHelpEngine *helpEngine;
+ bool closeNewTabIfNeeded;
+
+ friend class HelpViewer;
+ Qt::MouseButtons m_pressedButtons;
+ Qt::KeyboardModifiers m_keyboardModifiers;
};
HelpPage::HelpPage(CentralWidget *central, QHelpEngine *engine, QObject *parent)
- : QWebPage(parent), centralWidget(central), helpEngine(engine)
+ : QWebPage(parent)
+ , centralWidget(central)
+ , helpEngine(engine)
+ , closeNewTabIfNeeded(false)
+ , m_pressedButtons(Qt::NoButton)
+ , m_keyboardModifiers(Qt::NoModifier)
{
}
QWebPage *HelpPage::createWindow(QWebPage::WebWindowType)
{
- return centralWidget->newEmptyTab()->page();
+ HelpPage* newPage = static_cast<HelpPage*>(centralWidget->newEmptyTab()->page());
+ if (newPage)
+ newPage->closeNewTabIfNeeded = closeNewTabIfNeeded;
+ closeNewTabIfNeeded = false;
+ return newPage;
}
static bool isLocalUrl(const QUrl &url)
@@ -196,10 +211,24 @@ static bool isLocalUrl(const QUrl &url)
return false;
}
+void HelpPage::triggerAction(WebAction action, bool checked)
+{
+ switch (action) {
+ case OpenLinkInNewWindow:
+ closeNewTabIfNeeded = true;
+ default: // fall through
+ QWebPage::triggerAction(action, checked);
+ break;
+ }
+}
+
bool HelpPage::acceptNavigationRequest(QWebFrame *,
- const QNetworkRequest &request, QWebPage::NavigationType)
+ const QNetworkRequest &request, QWebPage::NavigationType type)
{
const QUrl &url = request.url();
+ const bool closeNewTab = closeNewTabIfNeeded;
+ closeNewTabIfNeeded = false;
+
if (isLocalUrl(url)) {
const QString& path = url.path();
if (path.endsWith(QLatin1String(".pdf"))) {
@@ -216,8 +245,22 @@ bool HelpPage::acceptNavigationRequest(QWebFrame *,
tmpFile.close();
}
QDesktopServices::openUrl(QUrl(tmpFile.fileName()));
+
+ if (closeNewTab)
+ QMetaObject::invokeMethod(CentralWidget::instance(), "closeTab");
return false;
}
+
+ if (type == QWebPage::NavigationTypeLinkClicked
+ && (m_keyboardModifiers & Qt::ControlModifier
+ || m_pressedButtons == Qt::MidButton)) {
+ HelpViewer* viewer = centralWidget->newEmptyTab();
+ if (viewer)
+ CentralWidget::instance()->setSource(url);
+ m_pressedButtons = Qt::NoButton;
+ m_keyboardModifiers = Qt::NoModifier;
+ return false;
+ }
return true;
}
@@ -332,6 +375,16 @@ void HelpViewer::actionChanged()
emit forwardAvailable(a->isEnabled());
}
+void HelpViewer::mousePressEvent(QMouseEvent *event)
+{
+ HelpPage *currentPage = static_cast<HelpPage*>(page());
+ if (currentPage) {
+ currentPage->m_pressedButtons = event->buttons();
+ currentPage->m_keyboardModifiers = event->modifiers();
+ }
+ QWebView::mousePressEvent(event);
+}
+
#else // !defined(QT_NO_WEBKIT)
HelpViewer::HelpViewer(QHelpEngine *engine, CentralWidget *parent)
diff --git a/tools/assistant/tools/assistant/helpviewer.h b/tools/assistant/tools/assistant/helpviewer.h
index af5c197..eea7340 100644
--- a/tools/assistant/tools/assistant/helpviewer.h
+++ b/tools/assistant/tools/assistant/helpviewer.h
@@ -107,6 +107,7 @@ Q_SIGNALS:
protected:
virtual void wheelEvent(QWheelEvent *);
void mouseReleaseEvent(QMouseEvent *e);
+ void mousePressEvent(QMouseEvent *event);
private Q_SLOTS:
void actionChanged();
diff --git a/tools/assistant/tools/assistant/indexwindow.cpp b/tools/assistant/tools/assistant/indexwindow.cpp
index 4bd6f4f..0beb5ee 100644
--- a/tools/assistant/tools/assistant/indexwindow.cpp
+++ b/tools/assistant/tools/assistant/indexwindow.cpp
@@ -189,13 +189,20 @@ void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index)
if (model) {
QString keyword = model->data(index, Qt::DisplayRole).toString();
QMap<QString, QUrl> links = model->linksForKeyword(keyword);
+
+ QUrl url;
if (links.count() > 1) {
TopicChooser tc(this, keyword, links);
- if (tc.exec() == QDialog::Accepted)
- CentralWidget::instance()->setSourceInNewTab(tc.link());
+ if (tc.exec() == QDialog::Accepted)
+ url = tc.link();
} else if (links.count() == 1) {
- CentralWidget::instance()->setSourceInNewTab(links.constBegin().value());
+ url = links.constBegin().value();
}
+
+ if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive))
+ CentralWidget::instance()->setSource(url);
+ else
+ CentralWidget::instance()->setSourceInNewTab(url);
}
}
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp
index 8a21409..bdc6c9a 100644
--- a/tools/linguist/lconvert/main.cpp
+++ b/tools/linguist/lconvert/main.cpp
@@ -205,6 +205,7 @@ int main(int argc, char *argv[])
qWarning() << qPrintable(cd.error());
return 2;
}
+ Translator::reportDuplicates(tr.resolveDuplicates(), inFiles[0].name, verbose);
for (int i = 1; i < inFiles.size(); ++i) {
Translator tr2;
@@ -212,6 +213,7 @@ int main(int argc, char *argv[])
qWarning() << qPrintable(cd.error());
return 2;
}
+ Translator::reportDuplicates(tr2.resolveDuplicates(), inFiles[i].name, verbose);
for (int j = 0; j < tr2.messageCount(); ++j)
tr.replaceSorted(tr2.message(j));
}
diff --git a/tools/linguist/linguist/messagemodel.cpp b/tools/linguist/linguist/messagemodel.cpp
index b049ab9..7a8063b 100644
--- a/tools/linguist/linguist/messagemodel.cpp
+++ b/tools/linguist/linguist/messagemodel.cpp
@@ -209,19 +209,19 @@ bool DataModel::load(const QString &fileName, bool *langGuessed, QWidget *parent
return false;
}
- QList<TranslatorMessage> dupes = tor.findDuplicates();
+ QSet<TranslatorMessagePtr> dupes = tor.resolveDuplicates();
if (!dupes.isEmpty()) {
QString err = tr("<qt>Duplicate messages found in '%1':").arg(Qt::escape(fileName));
int numdups = 0;
- foreach (const TranslatorMessage &msg, dupes) {
+ foreach (const TranslatorMessagePtr &msg, dupes) {
if (++numdups >= 5) {
err += tr("<p>[more duplicates omitted]");
break;
}
err += tr("<p>* Context: %1<br>* Source: %2")
- .arg(Qt::escape(msg.context()), Qt::escape(msg.sourceText()));
- if (!msg.comment().isEmpty())
- err += tr("<br>* Comment: %3").arg(Qt::escape(msg.comment()));
+ .arg(Qt::escape(msg->context()), Qt::escape(msg->sourceText()));
+ if (!msg->comment().isEmpty())
+ err += tr("<br>* Comment: %3").arg(Qt::escape(msg->comment()));
}
QMessageBox::warning(parent, QObject::tr("Qt Linguist"), err);
}
diff --git a/tools/linguist/lrelease/main.cpp b/tools/linguist/lrelease/main.cpp
index 0440325..7d0452f 100644
--- a/tools/linguist/lrelease/main.cpp
+++ b/tools/linguist/lrelease/main.cpp
@@ -93,19 +93,6 @@ static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbo
} else {
if (!cd.errors().isEmpty())
printOut(cd.error());
- const QList<TranslatorMessage> dupes = tor.findDuplicates();
- if (!dupes.isEmpty()) {
- qWarning("lrelease error: duplicate messages found in '%s':",
- qPrintable(tsFileName));
- foreach (const TranslatorMessage &msg, dupes) {
- qWarning("\n* Context: %s\n* Source: %s",
- qPrintable(msg.context()),
- qPrintable(msg.sourceText()));
- if (!msg.comment().isEmpty())
- qWarning("\n* Comment: %s", qPrintable(msg.comment()));
- }
- ok = false;
- }
}
return ok;
}
@@ -114,6 +101,8 @@ static bool releaseTranslator(Translator &tor, const QString &qmFileName,
bool verbose, bool ignoreUnfinished,
bool removeIdentical, TranslatorSaveMode mode)
{
+ Translator::reportDuplicates(tor.resolveDuplicates(), qmFileName, verbose);
+
if (verbose)
printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName));
if (removeIdentical) {
diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp
index b241857..8a70b55 100644
--- a/tools/linguist/lupdate/main.cpp
+++ b/tools/linguist/lupdate/main.cpp
@@ -150,6 +150,7 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
*fail = true;
continue;
}
+ tor.resolveDuplicates();
cd.clearErrors();
if (!codecForTr.isEmpty() && codecForTr != tor.codecName())
qWarning("lupdate warning: Codec for tr() '%s' disagrees with "
diff --git a/tools/linguist/shared/profileevaluator.cpp b/tools/linguist/shared/profileevaluator.cpp
index 173b46e..ec69156 100644
--- a/tools/linguist/shared/profileevaluator.cpp
+++ b/tools/linguist/shared/profileevaluator.cpp
@@ -258,8 +258,12 @@ bool ProFileEvaluator::Private::read(ProFile *pro)
return false;
}
+ m_block = 0;
+ m_commentItem = 0;
+ m_contNextLine = false;
m_syntaxError = false;
m_lineNo = 1;
+ m_blockstack.clear();
m_blockstack.push(pro);
QTextStream ts(&file);
@@ -1204,9 +1208,10 @@ bool ProFileEvaluator::Private::isActiveConfig(const QString &config, bool regex
QStringList ProFileEvaluator::Private::evaluateExpandFunction(const QString &func, const QString &arguments)
{
QStringList argumentsList = split_arg_list(arguments);
+
QStringList args;
for (int i = 0; i < argumentsList.count(); ++i)
- args += expandVariableReferences(argumentsList[i]);
+ args += expandVariableReferences(argumentsList[i]).join(Option::field_sep);
enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST,
E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
@@ -1693,10 +1698,11 @@ bool ProFileEvaluator::Private::evaluateConditionalFunction(const QString &funct
for (int mut = 0; mut < mutuals.count(); mut++) {
if (configs[i] == mutuals[mut].trimmed()) {
cond = (configs[i] == args[0]);
- break;
+ goto done_T_CONFIG;
}
}
}
+ done_T_CONFIG:
break;
}
case T_CONTAINS: {
@@ -1723,12 +1729,12 @@ bool ProFileEvaluator::Private::evaluateConditionalFunction(const QString &funct
for (int mut = 0; mut < mutuals.count(); mut++) {
if (val == mutuals[mut].trimmed()) {
cond = (regx.exactMatch(val) || val == args[1]);
- break;
+ goto done_T_CONTAINS;
}
}
}
}
-
+ done_T_CONTAINS:
break;
}
case T_COUNT: {
diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp
index d19b519..5563ac5 100644
--- a/tools/linguist/shared/qm.cpp
+++ b/tools/linguist/shared/qm.cpp
@@ -659,7 +659,6 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
msg.setComment(comment);
translator.append(msg);
}
- translator.resolveDualEncoded();
return ok;
}
diff --git a/tools/linguist/shared/translator.cpp b/tools/linguist/shared/translator.cpp
index 3721204..312bb71 100644
--- a/tools/linguist/shared/translator.cpp
+++ b/tools/linguist/shared/translator.cpp
@@ -416,38 +416,52 @@ void Translator::dropTranslations()
}
}
-QList<TranslatorMessage> Translator::findDuplicates() const
+QSet<TranslatorMessagePtr> Translator::resolveDuplicates()
{
- QHash<TranslatorMessage, int> dups;
- foreach (const TranslatorMessage &msg, m_messages)
- dups[msg]++;
- QList<TranslatorMessage> ret;
- QHash<TranslatorMessage, int>::ConstIterator it = dups.constBegin(), end = dups.constEnd();
- for (; it != end; ++it)
- if (it.value() > 1)
- ret.append(it.key());
- return ret;
-}
-
-void Translator::resolveDualEncoded()
-{
- QHash<TranslatorMessage, int> dups;
+ QSet<TranslatorMessagePtr> dups;
+ QHash<TranslatorMessagePtr, int> refs;
for (int i = 0; i < m_messages.count();) {
const TranslatorMessage &msg = m_messages.at(i);
- QHash<TranslatorMessage, int>::ConstIterator it = dups.constFind(msg);
- if (it != dups.constEnd()) {
+ QHash<TranslatorMessagePtr, int>::ConstIterator it = refs.constFind(msg);
+ if (it != refs.constEnd()) {
TranslatorMessage &omsg = m_messages[*it];
if (omsg.isUtf8() != msg.isUtf8() && !omsg.isNonUtf8()) {
+ // Dual-encoded message
omsg.setUtf8(true);
omsg.setNonUtf8(true);
- m_messages.removeAt(i);
- continue;
+ } else {
+ // Duplicate
+ dups.insert(omsg);
}
- // Regular dupe; will complain later
+ if (!omsg.isTranslated() && msg.isTranslated())
+ omsg.setTranslations(msg.translations());
+ m_messages.removeAt(i);
} else {
- dups[msg] = i;
+ refs[msg] = i;
+ ++i;
+ }
+ }
+ return dups;
+}
+
+void Translator::reportDuplicates(const QSet<TranslatorMessagePtr> &dupes,
+ const QString &fileName, bool verbose)
+{
+ if (!dupes.isEmpty()) {
+ if (!verbose) {
+ qWarning("Warning: dropping duplicate messages in '%s'\n(try -verbose for more info).",
+ qPrintable(fileName));
+ } else {
+ qWarning("Warning: dropping duplicate messages in '%s':", qPrintable(fileName));
+ foreach (const TranslatorMessagePtr &msg, dupes) {
+ qWarning("\n* Context: %s\n* Source: %s",
+ qPrintable(msg->context()),
+ qPrintable(msg->sourceText()));
+ if (!msg->comment().isEmpty())
+ qWarning("* Comment: %s", qPrintable(msg->comment()));
+ }
+ qWarning();
}
- ++i;
}
}
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index 0f83c1d..4e97000 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -132,9 +132,10 @@ public:
void stripNonPluralForms();
void stripIdenticalSourceTranslations();
void dropTranslations();
- QList<TranslatorMessage> findDuplicates() const;
- void resolveDualEncoded();
void makeFileNamesAbsolute(const QDir &originalPath);
+ QSet<TranslatorMessagePtr> resolveDuplicates();
+ static void reportDuplicates(const QSet<TranslatorMessagePtr> &dupes,
+ const QString &fileName, bool verbose);
void setCodecName(const QByteArray &name);
QByteArray codecName() const { return m_codecName; }
diff --git a/tools/linguist/shared/translatormessage.h b/tools/linguist/shared/translatormessage.h
index 363019e..7d31925 100644
--- a/tools/linguist/shared/translatormessage.h
+++ b/tools/linguist/shared/translatormessage.h
@@ -179,6 +179,32 @@ Q_DECLARE_TYPEINFO(TranslatorMessage, Q_MOVABLE_TYPE);
int qHash(const TranslatorMessage &msg);
+struct TranslatorMessagePtr {
+ TranslatorMessagePtr(const TranslatorMessage &tm)
+ {
+ ptr = &tm;
+ }
+
+ inline const TranslatorMessage *operator->() const
+ {
+ return ptr;
+ }
+
+ const TranslatorMessage *ptr;
+};
+
+Q_DECLARE_TYPEINFO(TranslatorMessagePtr, Q_MOVABLE_TYPE);
+
+static inline int qHash(TranslatorMessagePtr tmp)
+{
+ return qHash(*tmp.ptr);
+}
+
+static inline bool operator==(TranslatorMessagePtr tmp1, TranslatorMessagePtr tmp2)
+{
+ return *tmp1.ptr == *tmp2.ptr;
+}
+
QT_END_NAMESPACE
#endif // QT_NO_TRANSLATION
diff --git a/tools/linguist/shared/ts.cpp b/tools/linguist/shared/ts.cpp
index 8a6d365..22f2a1b 100644
--- a/tools/linguist/shared/ts.cpp
+++ b/tools/linguist/shared/ts.cpp
@@ -242,7 +242,7 @@ bool TSReader::read(Translator &translator)
STRING(userdata);
STRING(utf8);
STRING(value);
- STRING(version);
+ //STRING(version);
STRING(yes);
static const QString strextrans(QLatin1String("extra-"));
@@ -266,15 +266,13 @@ bool TSReader::read(Translator &translator)
QString currentFile;
QXmlStreamAttributes atts = attributes();
- QString version = atts.value(strversion).toString();
+ //QString version = atts.value(strversion).toString();
translator.setLanguageCode(atts.value(strlanguage).toString());
translator.setSourceLanguageCode(atts.value(strsourcelanguage).toString());
while (!atEnd()) {
readNext();
if (isEndElement()) {
// </TS> found, finish local loop
- if (version == QLatin1String("1.1"))
- translator.resolveDualEncoded();
break;
} else if (isWhiteSpace()) {
// ignore these, just whitespace