diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/tools/assistant/contentwindow.cpp | 60 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/contentwindow.h | 2 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.cpp | 83 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/helpviewer.h | 1 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/indexwindow.cpp | 63 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/indexwindow.h | 2 | ||||
-rw-r--r-- | tools/configure/tools.cpp | 35 | ||||
-rw-r--r-- | tools/linguist/lconvert/main.cpp | 2 | ||||
-rw-r--r-- | tools/linguist/linguist/messagemodel.cpp | 10 | ||||
-rw-r--r-- | tools/linguist/lrelease/main.cpp | 15 | ||||
-rw-r--r-- | tools/linguist/lupdate/main.cpp | 1 | ||||
-rw-r--r-- | tools/linguist/shared/profileevaluator.cpp | 19 | ||||
-rw-r--r-- | tools/linguist/shared/qm.cpp | 1 | ||||
-rw-r--r-- | tools/linguist/shared/translator.cpp | 58 | ||||
-rw-r--r-- | tools/linguist/shared/translator.h | 5 | ||||
-rw-r--r-- | tools/linguist/shared/translatormessage.h | 26 | ||||
-rw-r--r-- | tools/linguist/shared/ts.cpp | 6 |
17 files changed, 243 insertions, 146 deletions
diff --git a/tools/assistant/tools/assistant/contentwindow.cpp b/tools/assistant/tools/assistant/contentwindow.cpp index ef272e8..89060bd 100644 --- a/tools/assistant/tools/assistant/contentwindow.cpp +++ b/tools/assistant/tools/assistant/contentwindow.cpp @@ -118,19 +118,24 @@ void ContentWindow::keyPressEvent(QKeyEvent *e) bool ContentWindow::eventFilter(QObject *o, QEvent *e) { - if (m_contentWidget && o == m_contentWidget->viewport() && e->type() - == QEvent::MouseButtonRelease) { + if (m_contentWidget && o == m_contentWidget->viewport() + && e->type() == QEvent::MouseButtonRelease) { QMouseEvent *me = static_cast<QMouseEvent*>(e); - if (m_contentWidget->indexAt(me->pos()).isValid() - && me->button() == Qt::LeftButton) { - itemClicked(m_contentWidget->currentIndex()); - } else if (m_contentWidget->indexAt(me->pos()).isValid() - && me->button() == Qt::MidButton) { - QHelpContentModel *contentModel = - qobject_cast<QHelpContentModel*>(m_contentWidget->model()); - QHelpContentItem *itm = - contentModel->contentItemAt(m_contentWidget->currentIndex()); - CentralWidget::instance()->setSourceInNewTab(itm->url()); + QModelIndex index = m_contentWidget->indexAt(me->pos()); + QItemSelectionModel *sm = m_contentWidget->selectionModel(); + + if (index.isValid() && (sm && sm->isSelected(index))) { + if (me->button() == Qt::LeftButton) { + itemClicked(index); + } else if (me->button() == Qt::MidButton) { + QHelpContentModel *contentModel = + qobject_cast<QHelpContentModel*>(m_contentWidget->model()); + if (contentModel) { + QHelpContentItem *itm = contentModel->contentItemAt(index); + if (itm && !isPdfFile(itm)) + CentralWidget::instance()->setSourceInNewTab(itm->url()); + } + } } } return QWidget::eventFilter(o, e); @@ -141,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()); @@ -160,14 +168,20 @@ void ContentWindow::showContextMenu(const QPoint &pos) void ContentWindow::itemClicked(const QModelIndex &index) { - if (!index.isValid()) - return; QHelpContentModel *contentModel = qobject_cast<QHelpContentModel*>(m_contentWidget->model()); - QHelpContentItem *itm = - contentModel->contentItemAt(index); - if (itm) - emit linkActivated(itm->url()); + + if (contentModel) { + QHelpContentItem *itm = contentModel->contentItemAt(index); + if (itm) + emit linkActivated(itm->url()); + } +} + +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 9817f23..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,15 +211,33 @@ 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)) { - if (url.path().endsWith(QLatin1String("pdf"))) { - QString fileName = url.toString(); - fileName = QDir::tempPath() + QDir::separator() + fileName.right - (fileName.length() - fileName.lastIndexOf(QChar('/'))); + const QString& path = url.path(); + if (path.endsWith(QLatin1String(".pdf"))) { + const int lastDash = path.lastIndexOf(QChar('/')); + QString fileName = QDir::tempPath() + QDir::separator(); + if (lastDash < 0) + fileName += path; + else + fileName += path.mid(lastDash + 1, path.length()); QFile tmpFile(QDir::cleanPath(fileName)); if (tmpFile.open(QIODevice::ReadWrite)) { @@ -212,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; } @@ -328,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) @@ -396,15 +453,19 @@ void HelpViewer::zoomOut(int range) bool HelpViewer::launchedWithExternalApp(const QUrl &url) { - bool isPdf = url.path().endsWith(QLatin1String("pdf")); + bool isPdf = url.path().endsWith(QLatin1String(".pdf")); if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("ftp") || url.scheme() == QLatin1String("mailto") || isPdf) { bool launched = false; if (isPdf && url.scheme() == QLatin1String("qthelp")) { - QString fileName = url.toString(); - fileName = QDir::tempPath() + QDir::separator() + fileName.right - (fileName.length() - fileName.lastIndexOf(QLatin1Char('/'))); + const QString& path = url.path(); + const int lastDash = path.lastIndexOf(QChar('/')); + QString fileName = QDir::tempPath() + QDir::separator(); + if (lastDash < 0) + fileName += path; + else + fileName += path.mid(lastDash + 1, path.length()); QFile tmpFile(QDir::cleanPath(fileName)); if (tmpFile.open(QIODevice::ReadWrite)) { 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 e7575fa..0beb5ee 100644 --- a/tools/assistant/tools/assistant/indexwindow.cpp +++ b/tools/assistant/tools/assistant/indexwindow.cpp @@ -122,10 +122,9 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) m_indexWidget->setCurrentIndex(idx); break; case Qt::Key_Escape: - emit escapePressed(); + emit escapePressed(); break; - default: - ; + default: ; // stop complaining } } else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) { QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e); @@ -140,44 +139,15 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) if (curTab == action) m_indexWidget->activateCurrentItem(); else if (newTab == action) { - QHelpIndexModel *model = - qobject_cast<QHelpIndexModel*>(m_indexWidget->model()); - QString keyword = model->data(idx, Qt::DisplayRole).toString(); - if (model) { - QMap<QString, QUrl> links = model->linksForKeyword(keyword); - if (links.count() == 1) { - CentralWidget::instance()-> - setSourceInNewTab(links.constBegin().value()); - } else { - TopicChooser tc(this, keyword, links); - if (tc.exec() == QDialog::Accepted) { - CentralWidget::instance()->setSourceInNewTab(tc.link()); - } - } - } + open(m_indexWidget, idx); } } } else if (m_indexWidget && obj == m_indexWidget->viewport() && e->type() == QEvent::MouseButtonRelease) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e); QModelIndex idx = m_indexWidget->indexAt(mouseEvent->pos()); - if (idx.isValid() && mouseEvent->button()==Qt::MidButton) { - QHelpIndexModel *model = - qobject_cast<QHelpIndexModel*>(m_indexWidget->model()); - QString keyword = model->data(idx, Qt::DisplayRole).toString(); - if (model) { - QMap<QString, QUrl> links = model->linksForKeyword(keyword); - if (links.count() > 1) { - TopicChooser tc(this, keyword, links); - if (tc.exec() == QDialog::Accepted) { - CentralWidget::instance()->setSourceInNewTab(tc.link()); - } - } else if (links.count() == 1) { - CentralWidget::instance()-> - setSourceInNewTab(links.constBegin().value()); - } - } - } + if (idx.isValid() && mouseEvent->button()==Qt::MidButton) + open(m_indexWidget, idx); } #ifdef Q_OS_MAC else if (obj == m_indexWidget && e->type() == QEvent::KeyPress) { @@ -213,4 +183,27 @@ void IndexWindow::focusInEvent(QFocusEvent *e) } } +void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) +{ + QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model()); + 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) + url = tc.link(); + } else if (links.count() == 1) { + url = links.constBegin().value(); + } + + if (url.path().endsWith(QLatin1String(".pdf"), Qt::CaseInsensitive)) + CentralWidget::instance()->setSource(url); + else + CentralWidget::instance()->setSourceInNewTab(url); + } +} + QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/indexwindow.h b/tools/assistant/tools/assistant/indexwindow.h index f1f57f9..14ed83c 100644 --- a/tools/assistant/tools/assistant/indexwindow.h +++ b/tools/assistant/tools/assistant/indexwindow.h @@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE class QHelpIndexWidget; class QHelpEngine; +class QModelIndex; class IndexWindow : public QWidget { @@ -79,6 +80,7 @@ private slots: private: bool eventFilter(QObject *obj, QEvent *e); void focusInEvent(QFocusEvent *e); + void open(QHelpIndexWidget *indexWidget, const QModelIndex &index); QLineEdit *m_searchLineEdit; QHelpIndexWidget *m_indexWidget; diff --git a/tools/configure/tools.cpp b/tools/configure/tools.cpp index 5d12ea5..760c101 100644 --- a/tools/configure/tools.cpp +++ b/tools/configure/tools.cpp @@ -142,25 +142,28 @@ void Tools::checkLicense(QMap<QString,QString> &dictionary, QMap<QString,QString dictionary["EDITION"] = "GUIFramework"; dictionary["QT_EDITION"] = "QT_EDITION_DESKTOPLIGHT"; } + + if (platforms == 'X') { + dictionary["LICENSE_EXTENSION"] = "-ALLOS"; + } else if (strchr("3679ACDEHJKMSUWX", platforms)) { + dictionary["LICENSE_EXTENSION"] = "-EMBEDDED"; + } else if (strchr("4BFPQRTY", platforms)) { + dictionary["LICENSE_EXTENSION"] = "-DESKTOP"; + } } else if (strcmp(licenseSchema,"Z4M") == 0 || strcmp(licenseSchema,"R4M") == 0 || strcmp(licenseSchema,"Q4M") == 0) { if (products == 'B') { dictionary["EDITION"] = "Evaluation"; dictionary["QT_EDITION"] = "QT_EDITION_EVALUATION"; + dictionary["LICENSE_EXTENSION"] = "-EVALUATION"; } } - // Determine license extension ----------------------------------------------------------------- if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/.LICENSE")) { // Generic, no-suffix license dictionary["LICENSE_EXTENSION"] = QString(); - } else if (platforms == 'X') { - dictionary["LICENSE_EXTENSION"] = "-ALLOS"; - } else if (/*Windows CE */platforms == '6' || /*Embedded */ platforms == '8' || /*Embedded + Windows CE*/platforms == 'K' || /*Windows + Windows CE*/ platforms == 'H') { - dictionary["LICENSE_EXTENSION"] = "-EMBEDDED"; - } else if (/*Windows*/ platforms == 'R' || /*Mac+X11+Windows*/ platforms == 'F') { - dictionary["LICENSE_EXTENSION"] = "-DESKTOP"; - } else if (dictionary["EDITION"] == "Evaluation") { - dictionary["LICENSE_EXTENSION"] = "-EVALUATION"; + } else if (dictionary["LICENSE_EXTENSION"].isEmpty()) { + cout << "License file does not contain proper license key." << endl; + dictionary["DONE"] = "error"; } if (licenseType.isEmpty() || dictionary["EDITION"].isEmpty() @@ -170,19 +173,9 @@ void Tools::checkLicense(QMap<QString,QString> &dictionary, QMap<QString,QString return; } - // verify that we are licensed to use Qt for Windows if (dictionary["PLATFORM NAME"].contains("Windows CE")) { - // verify that we are licensed to use Qt for Windows AND Qt for Windows CE - if (platforms != 'H') { - cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl; - cout << "Please contact sales@trolltech.com to upgrade your license" << endl; - cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl; - cout << "Qt Open Source Edition if you intend to develop free software." << endl; - dictionary["DONE"] = "error"; - return; - } - } else { - if (!( platforms == 'R' || ( platforms == '6' )|| platforms == '8' )) { + // verify that we are licensed to use Qt for Windows CE + if (dictionary["LICENSE_EXTENSION"] != "-EMBEDDED" && dictionary["LICENSE_EXTENSION"] != "-ALLOS") { cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl; cout << "Please contact sales@trolltech.com to upgrade your license" << endl; cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl; diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp index 2842bc7..9ccc60e 100644 --- a/tools/linguist/lconvert/main.cpp +++ b/tools/linguist/lconvert/main.cpp @@ -210,6 +210,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; @@ -217,6 +218,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 f1fdb3a..3bcc998 100644 --- a/tools/linguist/lrelease/main.cpp +++ b/tools/linguist/lrelease/main.cpp @@ -94,19 +94,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; } @@ -115,6 +102,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 5869838..b537b6e 100644 --- a/tools/linguist/lupdate/main.cpp +++ b/tools/linguist/lupdate/main.cpp @@ -146,6 +146,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 aa529c1..ce53c27 100644 --- a/tools/linguist/shared/profileevaluator.cpp +++ b/tools/linguist/shared/profileevaluator.cpp @@ -157,11 +157,6 @@ ProFileEvaluator::Private::Private(ProFileEvaluator *q_) m_prevLineNo = 0; m_prevProFile = 0; m_verbose = true; - m_block = 0; - m_commentItem = 0; - m_syntaxError = 0; - m_lineNo = 0; - m_contNextLine = false; } bool ProFileEvaluator::Private::read(ProFile *pro) @@ -172,8 +167,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); @@ -1002,9 +1001,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, @@ -1265,10 +1265,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 CF_CONTAINS: { @@ -1295,12 +1296,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 CF_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 8908305..6b88b23 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -127,9 +127,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 |