From 2cb067878dd704e93919c55a32c3db0a24b44fa3 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 6 Nov 2011 17:01:23 +0100 Subject: [PATCH] Coding style, fixed cppcheck warnings + improved html highlighter - html highlighter is now highlighting with reg exps, no more with hard coded tags/tag options - all cppecheck warnings fixed + added script (cppcheck.sh) - introduced coding style + added astyle script (coding_style.sh) - fixed one mistake in czech translate + updated windows installer --- bin/locale/cs_CZ.qm | Bin 83377 -> 83377 bytes scripts/make-ca-bundle.sh | 3 + src/3rdparty/ecwin7.cpp | 35 +- src/3rdparty/ecwin7.h | 14 +- src/3rdparty/fancytabwidget.cpp | 703 +++++++++--------- src/3rdparty/fancytabwidget.h | 155 ++-- src/3rdparty/lineedit.cpp | 68 +- src/3rdparty/lineedit.h | 26 +- src/3rdparty/msvc2008.h | 243 +++--- src/3rdparty/qtlocalpeer.cpp | 58 +- src/3rdparty/qtlocalpeer.h | 27 +- src/3rdparty/qtlockedfile.cpp | 20 +- src/3rdparty/qtlockedfile.h | 20 +- src/3rdparty/qtlockedfile_unix.cpp | 54 +- src/3rdparty/qtlockedfile_win.cpp | 69 +- src/3rdparty/qtsingleapplication.cpp | 42 +- src/3rdparty/qtsingleapplication.h | 36 +- src/3rdparty/qtwin.cpp | 109 +-- src/3rdparty/qtwin.h | 6 +- src/3rdparty/squeezelabelv1.cpp | 4 +- src/3rdparty/squeezelabelv1.h | 4 +- src/3rdparty/squeezelabelv2.cpp | 4 +- src/3rdparty/squeezelabelv2.h | 4 +- src/3rdparty/stylehelper.cpp | 46 +- src/3rdparty/stylehelper.h | 9 +- src/adblock/adblockblockednetworkreply.cpp | 4 +- src/adblock/adblockblockednetworkreply.h | 6 +- src/adblock/adblockdialog.cpp | 40 +- src/adblock/adblockdialog.h | 2 +- src/adblock/adblockicon.cpp | 15 +- src/adblock/adblockmanager.cpp | 26 +- src/adblock/adblockmanager.h | 6 +- src/adblock/adblocknetwork.cpp | 27 +- src/adblock/adblocknetwork.h | 4 +- src/adblock/adblockpage.cpp | 45 +- src/adblock/adblockpage.h | 6 +- src/adblock/adblockrule.cpp | 51 +- src/adblock/adblocksubscription.cpp | 55 +- src/adblock/adblocksubscription.h | 2 +- src/app/autosaver.cpp | 10 +- src/app/commandlineoptions.cpp | 10 +- src/app/commandlineoptions.h | 4 +- src/app/mainapplication.cpp | 212 +++--- src/app/mainapplication.h | 6 +- src/app/profileupdater.cpp | 7 +- src/app/qupzilla.cpp | 295 +++++--- src/app/qupzilla.h | 14 +- src/autofill/autofillmodel.cpp | 82 +- src/autofill/autofillmodel.h | 2 +- src/autofill/autofillnotification.cpp | 10 +- src/autofill/autofillnotification.h | 5 +- src/bookmarks/bookmarkicon.cpp | 19 +- src/bookmarks/bookmarksmanager.cpp | 151 ++-- src/bookmarks/bookmarksmanager.h | 5 +- src/bookmarks/bookmarksmodel.cpp | 126 ++-- src/bookmarks/bookmarksmodel.h | 7 +- src/bookmarks/bookmarkstoolbar.cpp | 105 ++- src/bookmarks/bookmarkswidget.cpp | 17 +- src/bookmarks/bookmarkswidget.h | 5 +- src/bookmarksimport/bookmarksimportdialog.cpp | 67 +- src/bookmarksimport/bookmarksimportdialog.h | 7 +- src/bookmarksimport/chromeimporter.cpp | 8 +- src/bookmarksimport/firefoximporter.cpp | 12 +- src/bookmarksimport/operaimporter.cpp | 3 +- src/cookies/cookiejar.cpp | 28 +- src/cookies/cookiemanager.cpp | 32 +- src/cookies/cookiemanager.h | 5 +- .../desktopnotification.cpp | 27 +- .../desktopnotification.h | 5 +- .../desktopnotificationsfactory.cpp | 11 +- src/downloads/downloadfilehelper.cpp | 72 +- src/downloads/downloaditem.cpp | 99 ++- src/downloads/downloaditem.h | 5 +- src/downloads/downloadmanager.cpp | 81 +- src/downloads/downloadmanager.h | 7 +- src/downloads/downloadoptionsdialog.cpp | 8 +- src/downloads/downloadoptionsdialog.h | 5 +- src/history/historymanager.cpp | 89 ++- src/history/historymanager.h | 5 +- src/history/historymodel.cpp | 26 +- src/history/webhistoryinterface.cpp | 2 +- src/history/webhistoryinterface.h | 2 +- src/main.cpp | 7 +- src/navigation/locationbar.cpp | 41 +- src/navigation/locationbarsettings.cpp | 11 +- src/navigation/locationcompleter.cpp | 50 +- src/navigation/locationcompleter.h | 2 +- src/navigation/locationpopup.cpp | 6 +- src/navigation/navigationbar.cpp | 28 +- src/navigation/navigationbar.h | 2 +- src/navigation/reloadstopbutton.cpp | 2 +- src/navigation/reloadstopbutton.h | 2 +- src/navigation/websearchbar.cpp | 21 +- src/network/networkmanager.cpp | 121 +-- src/network/networkmanager.h | 2 +- src/network/networkmanagerproxy.cpp | 15 +- src/network/networkproxyfactory.cpp | 10 +- src/network/qupzillaschemehandler.cpp | 37 +- src/network/qupzillaschemehandler.h | 2 +- src/opensearch/editsearchengine.cpp | 3 +- src/opensearch/editsearchengine.h | 5 +- src/opensearch/opensearchengine.cpp | 83 ++- src/opensearch/opensearchengine.h | 20 +- src/opensearch/opensearchreader.cpp | 69 +- src/opensearch/opensearchreader.h | 4 +- src/opensearch/searchenginesdialog.cpp | 30 +- src/opensearch/searchenginesdialog.h | 9 +- src/opensearch/searchenginesmanager.cpp | 49 +- src/opensearch/searchenginesmanager.h | 3 +- src/other/aboutdialog.cpp | 20 +- src/other/aboutdialog.h | 5 +- src/other/browsinglibrary.cpp | 18 +- src/other/browsinglibrary.h | 11 +- src/other/clearprivatedata.cpp | 4 +- src/other/clearprivatedata.h | 5 +- src/other/pagescreen.h | 7 +- src/other/sourceviewer.cpp | 22 +- src/other/sourceviewersearch.cpp | 13 +- src/other/sourceviewersearch.h | 5 +- src/other/statusbarmessage.cpp | 18 +- src/other/statusbarmessage.h | 3 +- src/other/updater.cpp | 24 +- src/other/updater.h | 15 +- src/plugins/clicktoflash.cpp | 74 +- src/plugins/plugininterface.h | 2 +- src/plugins/pluginproxy.cpp | 43 +- src/plugins/plugins.cpp | 19 +- src/plugins/plugins.h | 2 +- src/plugins/webpluginfactory.cpp | 29 +- src/plugins/webpluginfactory.h | 2 +- src/preferences/acceptlanguage.cpp | 57 +- src/preferences/acceptlanguage.h | 5 +- src/preferences/autofillmanager.cpp | 36 +- src/preferences/autofillmanager.h | 5 +- src/preferences/pluginslist.cpp | 60 +- src/preferences/pluginslist.h | 5 +- src/preferences/preferences.cpp | 333 +++++---- src/preferences/preferences.h | 5 +- src/preferences/sslmanager.cpp | 32 +- src/preferences/sslmanager.h | 7 +- src/preferences/thememanager.cpp | 41 +- src/preferences/thememanager.h | 7 +- src/rss/rssmanager.cpp | 148 ++-- src/rss/rssmanager.h | 5 +- src/rss/rssnotification.h | 5 +- src/rss/rsswidget.cpp | 34 +- src/rss/rsswidget.h | 5 +- src/sidebar/bookmarkssidebar.cpp | 86 ++- src/sidebar/bookmarkssidebar.h | 5 +- src/sidebar/historysidebar.cpp | 80 +- src/sidebar/historysidebar.h | 5 +- src/sidebar/sidebar.cpp | 3 +- src/tools/animatedwidget.cpp | 10 +- src/tools/animatedwidget.h | 2 +- src/tools/buttonbox.cpp | 6 +- src/tools/buttonbox.h | 2 +- src/tools/buttonwithmenu.cpp | 33 +- src/tools/buttonwithmenu.h | 10 +- src/tools/certificateinfowidget.cpp | 303 ++++++-- src/tools/certificateinfowidget.h | 9 +- src/tools/clickablelabel.cpp | 6 +- src/tools/closedtabsmanager.cpp | 8 +- src/tools/closedtabsmanager.h | 3 +- src/tools/docktitlebarwidget.cpp | 2 +- src/tools/followredirectreply.cpp | 2 +- src/tools/globalfunctions.cpp | 32 +- src/tools/htmlhighlighter.cpp | 183 ++--- src/tools/htmlhighlighter.h | 7 +- src/tools/iconfetcher.cpp | 12 +- src/tools/iconprovider.cpp | 60 +- src/tools/progressbar.cpp | 12 +- src/tools/toolbutton.cpp | 15 +- src/tools/toolbutton.h | 6 +- src/tools/treewidget.cpp | 86 ++- src/tools/treewidget.h | 8 +- src/tools/widget.cpp | 2 +- src/tools/widget.h | 2 +- src/webview/searchtoolbar.cpp | 32 +- src/webview/searchtoolbar.h | 5 +- src/webview/siteinfo.cpp | 81 +- src/webview/siteinfo.h | 7 +- src/webview/siteinfowidget.cpp | 28 +- src/webview/siteinfowidget.h | 5 +- src/webview/tabbar.cpp | 83 ++- src/webview/tabwidget.cpp | 211 +++--- src/webview/tabwidget.h | 6 +- src/webview/webhistorywrapper.cpp | 14 +- src/webview/webhistorywrapper.h | 2 +- src/webview/webinspectordockwidget.cpp | 12 +- src/webview/webpage.cpp | 94 ++- src/webview/webpage.h | 5 +- src/webview/webtab.cpp | 11 +- src/webview/webview.cpp | 252 ++++--- translations/cs_CZ.ts | 2 +- windows/installer.nsi | 6 + 195 files changed, 4316 insertions(+), 3051 deletions(-) diff --git a/bin/locale/cs_CZ.qm b/bin/locale/cs_CZ.qm index b7eb68f49f6e2156dfe94c14df9c8a295e627d2f..be2fafdc0ce457f12b9b3c828e2a0ac23f55ef4a 100644 GIT binary patch delta 19 acmdnk&APFhwP6dRA`_$4b|ogperEtfAqB($ delta 19 acmdnk&APFhwP6dRA`_$Db|ogperEte%>}ps diff --git a/scripts/make-ca-bundle.sh b/scripts/make-ca-bundle.sh index b1e5790e9..fe683e894 100755 --- a/scripts/make-ca-bundle.sh +++ b/scripts/make-ca-bundle.sh @@ -1,2 +1,5 @@ #!/bin/bash cat /usr/share/ca-certificates/*/*.crt > ../other/ca-bundle.crt + +read -p "Press [ENTER] to close terminal" +exit diff --git a/src/3rdparty/ecwin7.cpp b/src/3rdparty/ecwin7.cpp index afae79ad0..b0f2f8086 100644 --- a/src/3rdparty/ecwin7.cpp +++ b/src/3rdparty/ecwin7.cpp @@ -21,11 +21,12 @@ // Windows only definitions #ifdef W7API -DEFINE_GUID(CLSID_TaskbarList,0x56fdf344,0xfd6d,0x11d0,0x95,0x8a,0x0,0x60,0x97,0xc9,0xa0,0x90); -DEFINE_GUID(IID_ITaskbarList3,0xea1afb91,0x9e28,0x4b86,0x90,0xE9,0x9e,0x9f,0x8a,0x5e,0xef,0xaf); +DEFINE_GUID(CLSID_TaskbarList, 0x56fdf344, 0xfd6d, 0x11d0, 0x95, 0x8a, 0x0, 0x60, 0x97, 0xc9, 0xa0, 0x90); +DEFINE_GUID(IID_ITaskbarList3, 0xea1afb91, 0x9e28, 0x4b86, 0x90, 0xE9, 0x9e, 0x9f, 0x8a, 0x5e, 0xef, 0xaf); // Constructor: variabiles initialization EcWin7::EcWin7() +, mTaskBar(NULL) { mOverlayIcon = NULL; } @@ -39,15 +40,14 @@ void EcWin7::init(WId wid) // Windows event handler callback function // (handles taskbar communication initial message) -bool EcWin7::winEvent(MSG * message, long * result) +bool EcWin7::winEvent(MSG* message, long* result) { - if (message->message == mTaskbarMessageId) - { + if (message->message == mTaskbarMessageId) { HRESULT hr = CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, - reinterpret_cast (&(mTaskbar))); + reinterpret_cast(&(mTaskbar))); *result = hr; return true; } @@ -72,24 +72,23 @@ void EcWin7::setProgressState(ToolBarProgressState state) void EcWin7::setOverlayIcon(QString iconName, QString description) { HICON oldIcon = NULL; - if (mOverlayIcon != NULL) oldIcon = mOverlayIcon; - if (iconName == "") - { + if (mOverlayIcon != NULL) { + oldIcon = mOverlayIcon; + } + if (iconName == "") { mTaskbar->SetOverlayIcon(mWindowId, NULL, NULL); mOverlayIcon = NULL; } - else - { + else { mOverlayIcon = (HICON) LoadImage(GetModuleHandle(NULL), - iconName.toStdWString().c_str(), - IMAGE_ICON, - 0, - 0, - NULL); + iconName.toStdWString().c_str(), + IMAGE_ICON, + 0, + 0, + NULL); mTaskbar->SetOverlayIcon(mWindowId, mOverlayIcon, description.toStdWString().c_str()); } - if ((oldIcon != NULL) && (oldIcon != mOverlayIcon)) - { + if ((oldIcon != NULL) && (oldIcon != mOverlayIcon)) { DestroyIcon(oldIcon); } } diff --git a/src/3rdparty/ecwin7.h b/src/3rdparty/ecwin7.h index dc986808f..a4e53824b 100644 --- a/src/3rdparty/ecwin7.h +++ b/src/3rdparty/ecwin7.h @@ -41,16 +41,16 @@ class EcWin7 { public: - // Initialization methods + // Initialization methods EcWin7(); void init(WId wid); - bool winEvent(MSG * message, long * result); + bool winEvent(MSG* message, long* result); - // Overlay icon handling - void setOverlayIcon(QString iconName, QString description); + // Overlay icon handling + void setOverlayIcon(QString iconName, QString description); - // Progress indicator handling - enum ToolBarProgressState { + // Progress indicator handling + enum ToolBarProgressState { NoProgress = 0, Indeterminate = 1, Normal = 2, @@ -63,7 +63,7 @@ public: private: WId mWindowId; UINT mTaskbarMessageId; - ITaskbarList3 *mTaskbar; + ITaskbarList3* mTaskbar; HICON mOverlayIcon; }; // Windows only data definitions - END diff --git a/src/3rdparty/fancytabwidget.cpp b/src/3rdparty/fancytabwidget.cpp index 35cc975f0..451301497 100644 --- a/src/3rdparty/fancytabwidget.cpp +++ b/src/3rdparty/fancytabwidget.cpp @@ -56,165 +56,173 @@ const int FancyTabBar::m_textPadding = 4; void FancyTabProxyStyle::drawControl( ControlElement element, const QStyleOption* option, - QPainter* p, const QWidget* widget) const { + QPainter* p, const QWidget* widget) const +{ - const QStyleOptionTabV3* v_opt = qstyleoption_cast(option); + const QStyleOptionTabV3* v_opt = qstyleoption_cast(option); - if (element != CE_TabBarTab || !v_opt) { - QProxyStyle::drawControl(element, option, p, widget); - return; - } + if (element != CE_TabBarTab || !v_opt) { + QProxyStyle::drawControl(element, option, p, widget); + return; + } - const QRect rect = v_opt->rect; - const bool selected = v_opt->state & State_Selected; - const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest; - const QString text = v_opt->text; + const QRect rect = v_opt->rect; + const bool selected = v_opt->state & State_Selected; + const bool vertical_tabs = v_opt->shape == QTabBar::RoundedWest; + const QString text = v_opt->text; + + if (selected) { + //background + p->save(); + QLinearGradient grad(rect.topLeft(), rect.topRight()); + grad.setColorAt(0, QColor(255, 255, 255, 140)); + grad.setColorAt(1, QColor(255, 255, 255, 210)); + p->fillRect(rect.adjusted(0, 0, 0, -1), grad); + p->restore(); + + //shadows + p->setPen(QColor(0, 0, 0, 110)); + p->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1)); + p->drawLine(rect.bottomLeft(), rect.bottomRight()); + p->setPen(QColor(0, 0, 0, 40)); + p->drawLine(rect.topLeft(), rect.bottomLeft()); + + //highlights + p->setPen(QColor(255, 255, 255, 50)); + p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2)); + p->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1)); + p->setPen(QColor(255, 255, 255, 40)); + p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); + p->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); + p->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1)); + } + + QTransform m; + if (vertical_tabs) { + m = QTransform::fromTranslate(rect.left(), rect.bottom()); + m.rotate(-90); + } + else { + m = QTransform::fromTranslate(rect.left(), rect.top()); + } + + const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size()); - if (selected) { - //background p->save(); - QLinearGradient grad(rect.topLeft(), rect.topRight()); - grad.setColorAt(0, QColor(255, 255, 255, 140)); - grad.setColorAt(1, QColor(255, 255, 255, 210)); - p->fillRect(rect.adjusted(0, 0, 0, -1), grad); - p->restore(); + p->setTransform(m); - //shadows - p->setPen(QColor(0, 0, 0, 110)); - p->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); - p->drawLine(rect.bottomLeft(), rect.bottomRight()); - p->setPen(QColor(0, 0, 0, 40)); - p->drawLine(rect.topLeft(), rect.bottomLeft()); + QRect icon_rect(QPoint(8, 0), v_opt->iconSize); + QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size()); + text_rect.setRight(draw_rect.width()); + icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2); - //highlights - p->setPen(QColor(255, 255, 255, 50)); - p->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); - p->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); - p->setPen(QColor(255, 255, 255, 40)); - p->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); - p->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); - p->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); - } - - QTransform m; - if (vertical_tabs) { - m = QTransform::fromTranslate(rect.left(), rect.bottom()); - m.rotate(-90); - } else { - m = QTransform::fromTranslate(rect.left(), rect.top()); - } - - const QRect draw_rect(QPoint(0, 0), m.mapRect(rect).size()); - - p->save(); - p->setTransform(m); - - QRect icon_rect(QPoint(8, 0), v_opt->iconSize); - QRect text_rect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size()); - text_rect.setRight(draw_rect.width()); - icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2); - - QFont boldFont(p->font()); - boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); - boldFont.setBold(true); - p->setFont(boldFont); - p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); - int textFlags = Qt::AlignHCenter | Qt::AlignVCenter; - p->drawText(text_rect, textFlags, text); - p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor()); + QFont boldFont(p->font()); + boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + p->setFont(boldFont); + p->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110)); + int textFlags = Qt::AlignHCenter | Qt::AlignVCenter; + p->drawText(text_rect, textFlags, text); + p->setPen(selected ? QColor(60, 60, 60) : Utils::StyleHelper::panelTextColor()); #ifndef Q_WS_MAC - if (widget) { - const QString fader_key = "tab_" + text + "_fader"; - const QString animation_key = "tab_" + text + "_animation"; + if (widget) { + const QString fader_key = "tab_" + text + "_fader"; + const QString animation_key = "tab_" + text + "_animation"; - const QString tab_hover = widget->property("tab_hover").toString(); - int fader = widget->property(fader_key.toUtf8().constData()).toInt(); - QPropertyAnimation* animation = widget->property(animation_key.toUtf8().constData()).value(); + const QString tab_hover = widget->property("tab_hover").toString(); + int fader = widget->property(fader_key.toUtf8().constData()).toInt(); + QPropertyAnimation* animation = widget->property(animation_key.toUtf8().constData()).value(); - if (!animation) { - QWidget* mut_widget = const_cast(widget); - fader = 0; - mut_widget->setProperty(fader_key.toUtf8().constData(), fader); - animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget); - connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update())); - mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation)); + if (!animation) { + QWidget* mut_widget = const_cast(widget); + fader = 0; + mut_widget->setProperty(fader_key.toUtf8().constData(), fader); + animation = new QPropertyAnimation(mut_widget, fader_key.toUtf8(), mut_widget); + connect(animation, SIGNAL(valueChanged(QVariant)), mut_widget, SLOT(update())); + mut_widget->setProperty(animation_key.toUtf8().constData(), QVariant::fromValue(animation)); + } + + if (text == tab_hover) { + if (animation->state() != QAbstractAnimation::Running && fader != 40) { + animation->stop(); + animation->setDuration(80); + animation->setEndValue(40); + animation->start(); + } + } + else { + if (animation->state() != QAbstractAnimation::Running && fader != 0) { + animation->stop(); + animation->setDuration(160); + animation->setEndValue(0); + animation->start(); + } + } + + if (!selected) { + p->save(); + QLinearGradient grad(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight()); + grad.setColorAt(0, Qt::transparent); + grad.setColorAt(0.5, QColor(255, 255, 255, fader)); + grad.setColorAt(1, Qt::transparent); + p->fillRect(draw_rect, grad); + p->setPen(QPen(grad, 1.0)); + p->drawLine(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight()); + p->drawLine(draw_rect.bottomRight(), vertical_tabs ? draw_rect.topRight() : draw_rect.bottomLeft()); + p->restore(); + } } - - if (text == tab_hover) { - if (animation->state() != QAbstractAnimation::Running && fader != 40) { - animation->stop(); - animation->setDuration(80); - animation->setEndValue(40); - animation->start(); - } - } else { - if (animation->state() != QAbstractAnimation::Running && fader != 0) { - animation->stop(); - animation->setDuration(160); - animation->setEndValue(0); - animation->start(); - } - } - - if (!selected) { - p->save(); - QLinearGradient grad(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight()); - grad.setColorAt(0, Qt::transparent); - grad.setColorAt(0.5, QColor(255, 255, 255, fader)); - grad.setColorAt(1, Qt::transparent); - p->fillRect(draw_rect, grad); - p->setPen(QPen(grad, 1.0)); - p->drawLine(draw_rect.topLeft(), vertical_tabs ? draw_rect.bottomLeft() : draw_rect.topRight()); - p->drawLine(draw_rect.bottomRight(), vertical_tabs ? draw_rect.topRight() : draw_rect.bottomLeft()); - p->restore(); - } - } #endif - Utils::StyleHelper::drawIconWithShadow(v_opt->icon, icon_rect, p, QIcon::Normal); + Utils::StyleHelper::drawIconWithShadow(v_opt->icon, icon_rect, p, QIcon::Normal); - p->drawText(text_rect.translated(0, -1), textFlags, text); + p->drawText(text_rect.translated(0, -1), textFlags, text); - p->restore(); + p->restore(); } -void FancyTabProxyStyle::polish(QWidget* widget) { - if (QString(widget->metaObject()->className()) == "QTabBar") { - widget->setMouseTracking(true); - widget->installEventFilter(this); - } - QProxyStyle::polish(widget); +void FancyTabProxyStyle::polish(QWidget* widget) +{ + if (QString(widget->metaObject()->className()) == "QTabBar") { + widget->setMouseTracking(true); + widget->installEventFilter(this); + } + QProxyStyle::polish(widget); } -void FancyTabProxyStyle::polish(QApplication* app) { - QProxyStyle::polish(app); +void FancyTabProxyStyle::polish(QApplication* app) +{ + QProxyStyle::polish(app); } -void FancyTabProxyStyle::polish(QPalette& palette) { - QProxyStyle::polish(palette); +void FancyTabProxyStyle::polish(QPalette &palette) +{ + QProxyStyle::polish(palette); } -bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e) { - QTabBar* bar = qobject_cast(o); - if (bar && (e->type() == QEvent::MouseMove || e->type() == QEvent::Leave)) { - QMouseEvent* event = static_cast(e); - const QString old_hovered_tab = bar->property("tab_hover").toString(); - const QString hovered_tab = e->type() == QEvent::Leave ? QString() : bar->tabText(bar->tabAt(event->pos())); - bar->setProperty("tab_hover", hovered_tab); +bool FancyTabProxyStyle::eventFilter(QObject* o, QEvent* e) +{ + QTabBar* bar = qobject_cast(o); + if (bar && (e->type() == QEvent::MouseMove || e->type() == QEvent::Leave)) { + QMouseEvent* event = static_cast(e); + const QString old_hovered_tab = bar->property("tab_hover").toString(); + const QString hovered_tab = e->type() == QEvent::Leave ? QString() : bar->tabText(bar->tabAt(event->pos())); + bar->setProperty("tab_hover", hovered_tab); - if (old_hovered_tab != hovered_tab) - bar->update(); - } + if (old_hovered_tab != hovered_tab) { + bar->update(); + } + } - return false; + return false; } FancyTab::FancyTab(QWidget* tabbar) - : QWidget(tabbar), tabbar(tabbar), m_fader(0) + : QWidget(tabbar), tabbar(tabbar), m_fader(0) { - animator.setPropertyName("fader"); - animator.setTargetObject(this); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + animator.setPropertyName("fader"); + animator.setTargetObject(this); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } void FancyTab::fadeIn() @@ -239,7 +247,7 @@ void FancyTab::setFader(float value) tabbar->update(); } -FancyTabBar::FancyTabBar(QWidget *parent) +FancyTabBar::FancyTabBar(QWidget* parent) : QWidget(parent) { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); @@ -265,42 +273,45 @@ FancyTabBar::~FancyTabBar() delete style(); } -QSize FancyTab::sizeHint() const { - QFont boldFont(font()); - boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); - boldFont.setBold(true); - QFontMetrics fm(boldFont); - int spacing = 8; - int width = 60 + spacing + 2; - int iconHeight = 32; - QSize ret(width, iconHeight + spacing + fm.height()); - return ret; +QSize FancyTab::sizeHint() const +{ + QFont boldFont(font()); + boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + QFontMetrics fm(boldFont); + int spacing = 8; + int width = 60 + spacing + 2; + int iconHeight = 32; + QSize ret(width, iconHeight + spacing + fm.height()); + return ret; } QSize FancyTabBar::tabSizeHint(bool minimum) const { - QFont boldFont(font()); - boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); - boldFont.setBold(true); - QFontMetrics fm(boldFont); - int spacing = 8; - int width = 60 + spacing + 2; - int iconHeight = minimum ? 0 : 32; - return QSize(width, iconHeight + spacing + fm.height()); + QFont boldFont(font()); + boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize()); + boldFont.setBold(true); + QFontMetrics fm(boldFont); + int spacing = 8; + int width = 60 + spacing + 2; + int iconHeight = minimum ? 0 : 32; + return QSize(width, iconHeight + spacing + fm.height()); } -void FancyTabBar::paintEvent(QPaintEvent *event) +void FancyTabBar::paintEvent(QPaintEvent* event) { Q_UNUSED(event) QPainter p(this); for (int i = 0; i < count(); ++i) - if (i != currentIndex()) + if (i != currentIndex()) { paintTab(&p, i); + } // paint active tab last, since it overlaps the neighbors - if (currentIndex() != -1) + if (currentIndex() != -1) { paintTab(&p, currentIndex()); + } } void FancyTab::enterEvent(QEvent*) @@ -330,12 +341,14 @@ QRect FancyTabBar::tabRect(int index) const return m_tabs[index]->geometry(); } -QString FancyTabBar::tabToolTip(int index) const { - return m_tabs[index]->toolTip(); +QString FancyTabBar::tabToolTip(int index) const +{ + return m_tabs[index]->toolTip(); } -void FancyTabBar::setTabToolTip(int index, const QString& toolTip) { - m_tabs[index]->setToolTip(toolTip); +void FancyTabBar::setTabToolTip(int index, const QString &toolTip) +{ + m_tabs[index]->setToolTip(toolTip); } // This keeps the sidebar responsive since @@ -346,7 +359,7 @@ void FancyTabBar::emitCurrentIndex() emit currentChanged(m_currentIndex); } -void FancyTabBar::mousePressEvent(QMouseEvent *e) +void FancyTabBar::mousePressEvent(QMouseEvent* e) { e->accept(); for (int index = 0; index < m_tabs.count(); ++index) { @@ -359,20 +372,22 @@ void FancyTabBar::mousePressEvent(QMouseEvent *e) } } -void FancyTabBar::addTab(const QIcon& icon, const QString& label) { - FancyTab *tab = new FancyTab(this); - tab->icon = icon; - tab->text = label; - m_tabs.append(tab); - qobject_cast(layout())->insertWidget(layout()->count()-1, tab); +void FancyTabBar::addTab(const QIcon &icon, const QString &label) +{ + FancyTab* tab = new FancyTab(this); + tab->icon = icon; + tab->text = label; + m_tabs.append(tab); + qobject_cast(layout())->insertWidget(layout()->count() - 1, tab); } -void FancyTabBar::addSpacer(int size) { - qobject_cast(layout())->insertSpacerItem(layout()->count()-1, - new QSpacerItem(0, size, QSizePolicy::Fixed, QSizePolicy::Maximum)); +void FancyTabBar::addSpacer(int size) +{ + qobject_cast(layout())->insertSpacerItem(layout()->count() - 1, + new QSpacerItem(0, size, QSizePolicy::Fixed, QSizePolicy::Maximum)); } -void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const +void FancyTabBar::paintTab(QPainter* painter, int tabIndex) const { if (!validIndex(tabIndex)) { qWarning("invalid index"); @@ -394,19 +409,19 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const //shadows painter->setPen(QColor(0, 0, 0, 110)); - painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1)); + painter->drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1)); painter->drawLine(rect.bottomLeft(), rect.bottomRight()); painter->setPen(QColor(0, 0, 0, 40)); painter->drawLine(rect.topLeft(), rect.bottomLeft()); //highlights painter->setPen(QColor(255, 255, 255, 50)); - painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2)); - painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1)); + painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2)); + painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1)); painter->setPen(QColor(255, 255, 255, 40)); painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()); painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)); - painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1)); + painter->drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1)); } QString tabText(painter->fontMetrics().elidedText(this->tabText(tabIndex), Qt::ElideMiddle, width())); @@ -447,7 +462,8 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const painter->restore(); } -void FancyTabBar::setCurrentIndex(int index) { +void FancyTabBar::setCurrentIndex(int index) +{ m_currentIndex = index; update(); emit currentChanged(m_currentIndex); @@ -461,19 +477,18 @@ void FancyTabBar::setCurrentIndex(int index) { class FancyColorButton : public QWidget { public: - FancyColorButton(QWidget *parent) - : m_parent(parent) - { + FancyColorButton(QWidget* parent) + : m_parent(parent) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); } - void mousePressEvent(QMouseEvent *ev) - { - if (ev->modifiers() & Qt::ShiftModifier) + void mousePressEvent(QMouseEvent* ev) { + if (ev->modifiers() & Qt::ShiftModifier) { Utils::StyleHelper::setBaseColor(QColorDialog::getColor(Utils::StyleHelper::requestedBaseColor(), m_parent)); + } } private: - QWidget *m_parent; + QWidget* m_parent; }; ////// @@ -481,163 +496,178 @@ private: ////// FancyTabWidget::FancyTabWidget(QWidget* parent) - : QWidget(parent), - mode_(Mode_None), - tab_bar_(NULL), - stack_(new QStackedLayout), - side_widget_(new QWidget), - side_layout_(new QVBoxLayout), - top_layout_(new QVBoxLayout), - use_background_(false), - menu_(NULL), - proxy_style_(new FancyTabProxyStyle) + : QWidget(parent), + mode_(Mode_None), + tab_bar_(NULL), + stack_(new QStackedLayout), + side_widget_(new QWidget), + side_layout_(new QVBoxLayout), + top_layout_(new QVBoxLayout), + use_background_(false), + menu_(NULL), + proxy_style_(new FancyTabProxyStyle) { - side_layout_->setSpacing(0); - side_layout_->setMargin(0); - side_layout_->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding)); + side_layout_->setSpacing(0); + side_layout_->setMargin(0); + side_layout_->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding)); - side_widget_->setLayout(side_layout_); - side_widget_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + side_widget_->setLayout(side_layout_); + side_widget_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - top_layout_->setMargin(0); - top_layout_->setSpacing(0); - top_layout_->addLayout(stack_); + top_layout_->setMargin(0); + top_layout_->setSpacing(0); + top_layout_->addLayout(stack_); - QHBoxLayout* main_layout = new QHBoxLayout; - main_layout->setMargin(0); - main_layout->setSpacing(1); - main_layout->addWidget(side_widget_); - main_layout->addLayout(top_layout_); - setLayout(main_layout); + QHBoxLayout* main_layout = new QHBoxLayout; + main_layout->setMargin(0); + main_layout->setSpacing(1); + main_layout->addWidget(side_widget_); + main_layout->addLayout(top_layout_); + setLayout(main_layout); } -void FancyTabWidget::AddTab(QWidget* tab, const QIcon& icon, const QString& label) { - stack_->addWidget(tab); - items_ << Item(icon, label); +void FancyTabWidget::AddTab(QWidget* tab, const QIcon &icon, const QString &label) +{ + stack_->addWidget(tab); + items_ << Item(icon, label); } -void FancyTabWidget::AddSpacer(int size) { - items_ << Item(size); +void FancyTabWidget::AddSpacer(int size) +{ + items_ << Item(size); } -void FancyTabWidget::SetBackgroundPixmap(const QPixmap& pixmap) { - background_pixmap_ = pixmap; - update(); +void FancyTabWidget::SetBackgroundPixmap(const QPixmap &pixmap) +{ + background_pixmap_ = pixmap; + update(); } -void FancyTabWidget::paintEvent(QPaintEvent*) { - if (!use_background_) - return; - - QPainter painter(this); - - QRect rect = side_widget_->rect().adjusted(0, 0, 1, 0); - rect = style()->visualRect(layoutDirection(), geometry(), rect); - Utils::StyleHelper::verticalGradient(&painter, rect, rect); - - if (!background_pixmap_.isNull()) { - QRect pixmap_rect(background_pixmap_.rect()); - pixmap_rect.moveTo(rect.topLeft()); - - while (pixmap_rect.top() < rect.bottom()) { - QRect source_rect(pixmap_rect.intersected(rect)); - source_rect.moveTo(0, 0); - painter.drawPixmap(pixmap_rect.topLeft(), background_pixmap_, source_rect); - pixmap_rect.moveTop(pixmap_rect.bottom() - 10); +void FancyTabWidget::paintEvent(QPaintEvent*) +{ + if (!use_background_) { + return; } - } - painter.setPen(Utils::StyleHelper::borderColor()); - painter.drawLine(rect.topRight(), rect.bottomRight()); + QPainter painter(this); - QColor light = Utils::StyleHelper::sidebarHighlight(); - painter.setPen(light); - painter.drawLine(rect.bottomLeft(), rect.bottomRight()); + QRect rect = side_widget_->rect().adjusted(0, 0, 1, 0); + rect = style()->visualRect(layoutDirection(), geometry(), rect); + Utils::StyleHelper::verticalGradient(&painter, rect, rect); + + if (!background_pixmap_.isNull()) { + QRect pixmap_rect(background_pixmap_.rect()); + pixmap_rect.moveTo(rect.topLeft()); + + while (pixmap_rect.top() < rect.bottom()) { + QRect source_rect(pixmap_rect.intersected(rect)); + source_rect.moveTo(0, 0); + painter.drawPixmap(pixmap_rect.topLeft(), background_pixmap_, source_rect); + pixmap_rect.moveTop(pixmap_rect.bottom() - 10); + } + } + + painter.setPen(Utils::StyleHelper::borderColor()); + painter.drawLine(rect.topRight(), rect.bottomRight()); + + QColor light = Utils::StyleHelper::sidebarHighlight(); + painter.setPen(light); + painter.drawLine(rect.bottomLeft(), rect.bottomRight()); } -int FancyTabWidget::current_index() const { - return stack_->currentIndex(); +int FancyTabWidget::current_index() const +{ + return stack_->currentIndex(); } -void FancyTabWidget::SetCurrentIndex(int index) { - if (FancyTabBar* bar = qobject_cast(tab_bar_)) { - bar->setCurrentIndex(index); - } else if (QTabBar* bar = qobject_cast(tab_bar_)) { - bar->setCurrentIndex(index); - } else { +void FancyTabWidget::SetCurrentIndex(int index) +{ + if (FancyTabBar* bar = qobject_cast(tab_bar_)) { + bar->setCurrentIndex(index); + } + else if (QTabBar* bar = qobject_cast(tab_bar_)) { + bar->setCurrentIndex(index); + } + else { + stack_->setCurrentIndex(index); + } +} + +void FancyTabWidget::ShowWidget(int index) +{ stack_->setCurrentIndex(index); - } + emit CurrentChanged(index); } -void FancyTabWidget::ShowWidget(int index) { - stack_->setCurrentIndex(index); - emit CurrentChanged(index); +void FancyTabWidget::AddBottomWidget(QWidget* widget) +{ + top_layout_->addWidget(widget); } -void FancyTabWidget::AddBottomWidget(QWidget* widget) { - top_layout_->addWidget(widget); -} +void FancyTabWidget::SetMode(Mode mode) +{ + // Remove previous tab bar + delete tab_bar_; + tab_bar_ = NULL; -void FancyTabWidget::SetMode(Mode mode) { - // Remove previous tab bar - delete tab_bar_; - tab_bar_ = NULL; + use_background_ = false; - use_background_ = false; - - // Create new tab bar - switch (mode) { + // Create new tab bar + switch (mode) { case Mode_None: default: - qDebug() << "Unknown fancy tab mode" << mode; - // fallthrough + qDebug() << "Unknown fancy tab mode" << mode; + // fallthrough case Mode_LargeSidebar: { - FancyTabBar* bar = new FancyTabBar(this); - side_layout_->insertWidget(0, bar); - tab_bar_ = bar; + FancyTabBar* bar = new FancyTabBar(this); + side_layout_->insertWidget(0, bar); + tab_bar_ = bar; - foreach (const Item& item, items_) { - if (item.type_ == Item::Type_Spacer) - bar->addSpacer(item.spacer_size_); - else - bar->addTab(item.tab_icon_, item.tab_label_); - } + foreach(const Item & item, items_) { + if (item.type_ == Item::Type_Spacer) { + bar->addSpacer(item.spacer_size_); + } + else { + bar->addTab(item.tab_icon_, item.tab_label_); + } + } - bar->setCurrentIndex(stack_->currentIndex()); - connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int))); + bar->setCurrentIndex(stack_->currentIndex()); + connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int))); - use_background_ = true; + use_background_ = true; - break; + break; } case Mode_Tabs: - MakeTabBar(QTabBar::RoundedNorth, true, false, false); - break; + MakeTabBar(QTabBar::RoundedNorth, true, false, false); + break; case Mode_IconOnlyTabs: - MakeTabBar(QTabBar::RoundedNorth, false, true, false); - break; + MakeTabBar(QTabBar::RoundedNorth, false, true, false); + break; case Mode_SmallSidebar: - MakeTabBar(QTabBar::RoundedWest, true, true, true); - use_background_ = true; - break; + MakeTabBar(QTabBar::RoundedWest, true, true, true); + use_background_ = true; + break; case Mode_PlainSidebar: - MakeTabBar(QTabBar::RoundedWest, true, true, false); - break; - } + MakeTabBar(QTabBar::RoundedWest, true, true, false); + break; + } - tab_bar_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + tab_bar_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - mode_ = mode; - emit ModeChanged(mode); - update(); + mode_ = mode; + emit ModeChanged(mode); + update(); } -void FancyTabWidget::contextMenuEvent(QContextMenuEvent* e) { +void FancyTabWidget::contextMenuEvent(QContextMenuEvent* e) +{ Q_UNUSED(e) // if (!menu_) { // menu_ = new QMenu(this); @@ -658,57 +688,66 @@ void FancyTabWidget::contextMenuEvent(QContextMenuEvent* e) { } void FancyTabWidget::AddMenuItem(QSignalMapper* mapper, QActionGroup* group, - const QString& text, Mode mode) { - QAction* action = group->addAction(text); - action->setCheckable(true); - mapper->setMapping(action, mode); - connect(action, SIGNAL(triggered()), mapper, SLOT(map())); + const QString &text, Mode mode) +{ + QAction* action = group->addAction(text); + action->setCheckable(true); + mapper->setMapping(action, mode); + connect(action, SIGNAL(triggered()), mapper, SLOT(map())); - if (mode == mode_) - action->setChecked(true); + if (mode == mode_) { + action->setChecked(true); + } } void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons, - bool fancy) { - QTabBar* bar = new QTabBar(this); - bar->setShape(shape); - bar->setDocumentMode(true); - bar->setUsesScrollButtons(true); + bool fancy) +{ + QTabBar* bar = new QTabBar(this); + bar->setShape(shape); + bar->setDocumentMode(true); + bar->setUsesScrollButtons(true); - if (shape == QTabBar::RoundedWest) { - bar->setIconSize(QSize(22, 22)); - } - - if (fancy) { - bar->setStyle(proxy_style_); - } - - if (shape == QTabBar::RoundedNorth) - top_layout_->insertWidget(0, bar); - else - side_layout_->insertWidget(0, bar); - - foreach (const Item& item, items_) { - if (item.type_ != Item::Type_Tab) - continue; - - QString label = item.tab_label_; if (shape == QTabBar::RoundedWest) { - label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100); + bar->setIconSize(QSize(22, 22)); } - int tab_id = -1; - if (icons && text) - tab_id = bar->addTab(item.tab_icon_, label); - else if (icons) - tab_id = bar->addTab(item.tab_icon_, QString()); - else if (text) - tab_id = bar->addTab(label); + if (fancy) { + bar->setStyle(proxy_style_); + } - bar->setTabToolTip(tab_id, item.tab_label_); - } + if (shape == QTabBar::RoundedNorth) { + top_layout_->insertWidget(0, bar); + } + else { + side_layout_->insertWidget(0, bar); + } - bar->setCurrentIndex(stack_->currentIndex()); - connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int))); - tab_bar_ = bar; + foreach(const Item & item, items_) { + if (item.type_ != Item::Type_Tab) { + continue; + } + + QString label = item.tab_label_; + if (shape == QTabBar::RoundedWest) { + label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100); + } + + int tab_id = -1; + if (icons && text) { + tab_id = bar->addTab(item.tab_icon_, label); + } + else if (icons) { + tab_id = bar->addTab(item.tab_icon_, QString()); + } + else if (text) { + tab_id = bar->addTab(label); + } + + bar->setTabToolTip(tab_id, item.tab_label_); + } + + bar->setCurrentIndex(stack_->currentIndex()); + connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int))); + tab_bar_ = bar; } diff --git a/src/3rdparty/fancytabwidget.h b/src/3rdparty/fancytabwidget.h index 67059778a..337644e5e 100644 --- a/src/3rdparty/fancytabwidget.h +++ b/src/3rdparty/fancytabwidget.h @@ -45,29 +45,33 @@ class QStackedLayout; class QStatusBar; class QVBoxLayout; -namespace Core { -namespace Internal { +namespace Core +{ +namespace Internal +{ -class FancyTabProxyStyle : public QProxyStyle { - Q_OBJECT +class FancyTabProxyStyle : public QProxyStyle +{ + Q_OBJECT public: - void drawControl(ControlElement element, const QStyleOption* option, - QPainter* painter, const QWidget* widget) const; - void polish(QWidget* widget); - void polish(QApplication* app); - void polish(QPalette& palette); + void drawControl(ControlElement element, const QStyleOption* option, + QPainter* painter, const QWidget* widget) const; + void polish(QWidget* widget); + void polish(QApplication* app); + void polish(QPalette &palette); protected: - bool eventFilter(QObject* o, QEvent* e); + bool eventFilter(QObject* o, QEvent* e); }; -class FancyTab : public QWidget{ +class FancyTab : public QWidget +{ Q_OBJECT Q_PROPERTY(float fader READ fader WRITE setFader) public: - FancyTab(QWidget *tabbar); + FancyTab(QWidget* tabbar); float fader() { return m_fader; } void setFader(float value); @@ -80,12 +84,12 @@ public: QString text; protected: - void enterEvent(QEvent *); - void leaveEvent(QEvent *); + void enterEvent(QEvent*); + void leaveEvent(QEvent*); private: QPropertyAnimation animator; - QWidget *tabbar; + QWidget* tabbar; float m_fader; }; @@ -94,12 +98,12 @@ class FancyTabBar : public QWidget Q_OBJECT public: - FancyTabBar(QWidget *parent = 0); + FancyTabBar(QWidget* parent = 0); ~FancyTabBar(); - void paintEvent(QPaintEvent *event); - void paintTab(QPainter *painter, int tabIndex) const; - void mousePressEvent(QMouseEvent *); + void paintEvent(QPaintEvent* event); + void paintTab(QPainter* painter, int tabIndex) const; + void mousePressEvent(QMouseEvent*); bool validIndex(int index) const { return index >= 0 && index < m_tabs.count(); } QSize sizeHint() const; @@ -108,13 +112,13 @@ public: void addTab(const QIcon &icon, const QString &label); void addSpacer(int size = 40); void removeTab(int index) { - FancyTab *tab = m_tabs.takeAt(index); + FancyTab* tab = m_tabs.takeAt(index); delete tab; } void setCurrentIndex(int index); int currentIndex() const { return m_currentIndex; } - void setTabToolTip(int index, const QString& toolTip); + void setTabToolTip(int index, const QString &toolTip); QString tabToolTip(int index) const; QIcon tabIcon(int index) const {return m_tabs.at(index)->icon; } @@ -138,87 +142,88 @@ private: }; -class FancyTabWidget : public QWidget { +class FancyTabWidget : public QWidget +{ Q_OBJECT Q_PROPERTY(QPixmap bgPixmap READ bgPixmap WRITE SetBackgroundPixmap) public: - FancyTabWidget(QWidget* parent = 0); + FancyTabWidget(QWidget* parent = 0); - // Values are persisted - only add to the end - enum Mode { - Mode_None = 0, + // Values are persisted - only add to the end + enum Mode { + Mode_None = 0, - Mode_LargeSidebar = 1, - Mode_SmallSidebar = 2, - Mode_Tabs = 3, - Mode_IconOnlyTabs = 4, - Mode_PlainSidebar = 5, - }; - - struct Item { - Item(const QIcon& icon, const QString& label) - : type_(Type_Tab), tab_label_(label), tab_icon_(icon), spacer_size_(0) {} - Item(int size) : type_(Type_Spacer), spacer_size_(size) {} - - enum Type { - Type_Tab, - Type_Spacer, + Mode_LargeSidebar = 1, + Mode_SmallSidebar = 2, + Mode_Tabs = 3, + Mode_IconOnlyTabs = 4, + Mode_PlainSidebar = 5, }; - Type type_; - QString tab_label_; - QIcon tab_icon_; - int spacer_size_; - }; + struct Item { + Item(const QIcon &icon, const QString &label) + : type_(Type_Tab), tab_label_(label), tab_icon_(icon), spacer_size_(0) {} + Item(int size) : type_(Type_Spacer), spacer_size_(size) {} - void AddTab(QWidget *tab, const QIcon &icon, const QString &label); - void AddSpacer(int size = 40); - void SetBackgroundPixmap(const QPixmap& pixmap); + enum Type { + Type_Tab, + Type_Spacer, + }; - void AddBottomWidget(QWidget* widget); + Type type_; + QString tab_label_; + QIcon tab_icon_; + int spacer_size_; + }; - int current_index() const; - Mode mode() const { return mode_; } - QPixmap bgPixmap() { return background_pixmap_; } + void AddTab(QWidget* tab, const QIcon &icon, const QString &label); + void AddSpacer(int size = 40); + void SetBackgroundPixmap(const QPixmap &pixmap); + + void AddBottomWidget(QWidget* widget); + + int current_index() const; + Mode mode() const { return mode_; } + QPixmap bgPixmap() { return background_pixmap_; } public slots: - void SetCurrentIndex(int index); - void SetMode(Mode mode); - void SetMode(int mode) { SetMode(Mode(mode)); } + void SetCurrentIndex(int index); + void SetMode(Mode mode); + void SetMode(int mode) { SetMode(Mode(mode)); } signals: - void CurrentChanged(int index); - void ModeChanged(FancyTabWidget::Mode mode); + void CurrentChanged(int index); + void ModeChanged(FancyTabWidget::Mode mode); protected: - void paintEvent(QPaintEvent *event); - void contextMenuEvent(QContextMenuEvent* e); + void paintEvent(QPaintEvent* event); + void contextMenuEvent(QContextMenuEvent* e); private slots: - void ShowWidget(int index); + void ShowWidget(int index); private: - void MakeTabBar(QTabBar::Shape shape, bool text, bool icons, bool fancy); - void AddMenuItem(QSignalMapper* mapper, QActionGroup* group, - const QString& text, Mode mode); + void MakeTabBar(QTabBar::Shape shape, bool text, bool icons, bool fancy); + void AddMenuItem(QSignalMapper* mapper, QActionGroup* group, + const QString &text, Mode mode); - Mode mode_; - QList items_; + Mode mode_; + QList items_; - QWidget* tab_bar_; - QStackedLayout* stack_; - QPixmap background_pixmap_; - QWidget* side_widget_; - QVBoxLayout* side_layout_; - QVBoxLayout* top_layout_; + QWidget* tab_bar_; + QStackedLayout* stack_; + QPixmap background_pixmap_; + QWidget* side_widget_; + QVBoxLayout* side_layout_; + QVBoxLayout* top_layout_; - bool use_background_; + bool use_background_; - QMenu* menu_; + QMenu* menu_; - FancyTabProxyStyle* proxy_style_; + FancyTabProxyStyle* proxy_style_; }; } // namespace Internal diff --git a/src/3rdparty/lineedit.cpp b/src/3rdparty/lineedit.cpp index 0cd2330bf..373784946 100644 --- a/src/3rdparty/lineedit.cpp +++ b/src/3rdparty/lineedit.cpp @@ -7,19 +7,20 @@ #include #include -SideWidget::SideWidget(QWidget *parent) +SideWidget::SideWidget(QWidget* parent) : QWidget(parent) { } -bool SideWidget::event(QEvent *event) +bool SideWidget::event(QEvent* event) { - if (event->type() == QEvent::LayoutRequest) + if (event->type() == QEvent::LayoutRequest) { emit sizeHintChanged(); + } return QWidget::event(event); } -LineEdit::LineEdit(QWidget *parent) +LineEdit::LineEdit(QWidget* parent) : QLineEdit(parent) , m_leftLayout(0) , m_rightLayout(0) @@ -28,7 +29,7 @@ LineEdit::LineEdit(QWidget *parent) init(); } -LineEdit::LineEdit(const QString &contents, QWidget *parent) +LineEdit::LineEdit(const QString &contents, QWidget* parent) : QLineEdit(contents, parent) , m_leftWidget(0) , m_rightWidget(0) @@ -51,22 +52,26 @@ void LineEdit::init() m_leftLayout = new QHBoxLayout(m_leftWidget); m_leftLayout->setContentsMargins(0, 0, 0, 0); - if (isRightToLeft()) + if (isRightToLeft()) { m_leftLayout->setDirection(QBoxLayout::RightToLeft); - else + } + else { m_leftLayout->setDirection(QBoxLayout::LeftToRight); + } m_leftLayout->setSizeConstraint(QLayout::SetFixedSize); m_rightWidget = new SideWidget(this); m_rightWidget->resize(0, 0); m_rightLayout = new QHBoxLayout(m_rightWidget); - if (isRightToLeft()) + if (isRightToLeft()) { m_rightLayout->setDirection(QBoxLayout::RightToLeft); - else + } + else { m_rightLayout->setDirection(QBoxLayout::LeftToRight); + } m_rightLayout->setContentsMargins(0, 0, 0, 0); - QSpacerItem *horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + QSpacerItem* horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); m_rightLayout->addItem(horizontalSpacer); setWidgetSpacing(3); @@ -76,13 +81,14 @@ void LineEdit::init() this, SLOT(updateTextMargins())); } -bool LineEdit::event(QEvent *event) +bool LineEdit::event(QEvent* event) { if (event->type() == QEvent::LayoutDirectionChange) { if (isRightToLeft()) { m_leftLayout->setDirection(QBoxLayout::RightToLeft); m_rightLayout->setDirection(QBoxLayout::RightToLeft); - } else { + } + else { m_leftLayout->setDirection(QBoxLayout::LeftToRight); m_rightLayout->setDirection(QBoxLayout::LeftToRight); } @@ -90,25 +96,29 @@ bool LineEdit::event(QEvent *event) return QLineEdit::event(event); } -void LineEdit::addWidget(QWidget *widget, WidgetPosition position) +void LineEdit::addWidget(QWidget* widget, WidgetPosition position) { - if (!widget) + if (!widget) { return; + } bool rtl = isRightToLeft(); - if (rtl) + if (rtl) { position = (position == LeftSide) ? RightSide : LeftSide; + } if (position == LeftSide) { m_leftLayout->addWidget(widget); - } else { + } + else { m_rightLayout->insertWidget(1, widget); } } -void LineEdit::removeWidget(QWidget *widget) +void LineEdit::removeWidget(QWidget* widget) { - if (!widget) + if (!widget) { return; + } m_leftLayout->removeWidget(widget); m_rightLayout->removeWidget(widget); @@ -131,22 +141,27 @@ int LineEdit::textMargin(WidgetPosition position) const { int spacing = m_rightLayout->spacing(); int w = 0; - if (position == LeftSide) + if (position == LeftSide) { w = m_leftWidget->sizeHint().width(); - else + } + else { w = m_rightWidget->sizeHint().width(); - if (w == 0) + } + if (w == 0) { return 0; + } return w + spacing * 2; } void LineEdit::updateTextMargins() { int left; - if (m_leftMargin == 0) + if (m_leftMargin == 0) { left = textMargin(LineEdit::LeftSide); - else + } + else { left = m_leftMargin; + } int right = textMargin(LineEdit::RightSide); int top = 0; int bottom = 0; @@ -169,8 +184,9 @@ void LineEdit::updateSideWidgetLocations() if (m_leftLayout->count() > 0) { int leftHeight = midHeight - m_leftWidget->height() / 2; int leftWidth = m_leftWidget->width(); - if (leftWidth == 0) + if (leftWidth == 0) { leftHeight = midHeight - m_leftWidget->sizeHint().height() / 2; + } m_leftWidget->move(textRect.x(), leftHeight); } textRect.setX(left); @@ -179,7 +195,7 @@ void LineEdit::updateSideWidgetLocations() m_rightWidget->setGeometry(textRect); } -void LineEdit::resizeEvent(QResizeEvent *event) +void LineEdit::resizeEvent(QResizeEvent* event) { updateSideWidgetLocations(); QLineEdit::resizeEvent(event); @@ -195,7 +211,7 @@ void LineEdit::setInactiveText(const QString &text) m_inactiveText = text; } -void LineEdit::paintEvent(QPaintEvent *event) +void LineEdit::paintEvent(QPaintEvent* event) { QLineEdit::paintEvent(event); if (text().isEmpty() && !m_inactiveText.isEmpty() && !hasFocus()) { diff --git a/src/3rdparty/lineedit.h b/src/3rdparty/lineedit.h index 62ac72cef..78e234e11 100644 --- a/src/3rdparty/lineedit.h +++ b/src/3rdparty/lineedit.h @@ -54,24 +54,24 @@ public: RightSide }; - LineEdit(QWidget *parent = 0); - LineEdit(const QString &contents, QWidget *parent = 0); + LineEdit(QWidget* parent = 0); + LineEdit(const QString &contents, QWidget* parent = 0); - void addWidget(QWidget *widget, WidgetPosition position); - void removeWidget(QWidget *widget); + void addWidget(QWidget* widget, WidgetPosition position); + void removeWidget(QWidget* widget); void setWidgetSpacing(int spacing); int widgetSpacing() const; int textMargin(WidgetPosition position) const; QString inactiveText() const; void setInactiveText(const QString &text); - void paintEvent(QPaintEvent *event); + void paintEvent(QPaintEvent* event); void setLeftMargin(int margin); protected: - void resizeEvent(QResizeEvent *event); - bool event(QEvent *event); + void resizeEvent(QResizeEvent* event); + bool event(QEvent* event); protected slots: void updateTextMargins(); @@ -80,10 +80,10 @@ private: void init(); void updateSideWidgetLocations(); - SideWidget *m_leftWidget; - SideWidget *m_rightWidget; - QHBoxLayout *m_leftLayout; - QHBoxLayout *m_rightLayout; + SideWidget* m_leftWidget; + SideWidget* m_rightWidget; + QHBoxLayout* m_leftLayout; + QHBoxLayout* m_rightLayout; QString m_inactiveText; int m_leftMargin; }; @@ -97,10 +97,10 @@ signals: void sizeHintChanged(); public: - SideWidget(QWidget *parent = 0); + SideWidget(QWidget* parent = 0); protected: - bool event(QEvent *event); + bool event(QEvent* event); }; diff --git a/src/3rdparty/msvc2008.h b/src/3rdparty/msvc2008.h index ad30cf4f9..bf32ad650 100644 --- a/src/3rdparty/msvc2008.h +++ b/src/3rdparty/msvc2008.h @@ -23,83 +23,81 @@ #ifndef __IObjectArray_FWD_DEFINED__ #define __IObjectArray_FWD_DEFINED__ typedef interface IObjectArray IObjectArray; -#endif /* __IObjectArray_FWD_DEFINED__ */ +#endif /* __IObjectArray_FWD_DEFINED__ */ #ifndef __IObjectCollection_FWD_DEFINED__ #define __IObjectCollection_FWD_DEFINED__ typedef interface IObjectCollection IObjectCollection; -#endif /* __IObjectCollection_FWD_DEFINED__ */ +#endif /* __IObjectCollection_FWD_DEFINED__ */ /* header files for imported files */ #include "oaidl.h" #include "ocidl.h" #ifdef __cplusplus -extern "C"{ +extern "C" { #endif -/* - **************************************************************************************************** - IObjectArray + /* + **************************************************************************************************** + IObjectArray - - **************************************************************************************************** -*/ + + **************************************************************************************************** + */ #ifndef __IObjectArray_INTERFACE_DEFINED__ #define __IObjectArray_INTERFACE_DEFINED__ -/* interface IObjectArray */ -/* [unique][object][uuid][helpstring] */ + /* interface IObjectArray */ + /* [unique][object][uuid][helpstring] */ -EXTERN_C const IID IID_IObjectArray; + EXTERN_C const IID IID_IObjectArray; -MIDL_INTERFACE("92CA9DCD-5622-4bba-A805-5E9F541BD8C9") -IObjectArray : public IUnknown -{ + MIDL_INTERFACE("92CA9DCD-5622-4bba-A805-5E9F541BD8C9") +IObjectArray : public IUnknown { public: - virtual HRESULT STDMETHODCALLTYPE GetCount( - /* [out] */ __RPC__out UINT *pcObjects) = 0; + virtual HRESULT STDMETHODCALLTYPE GetCount( + /* [out] */ __RPC__out UINT* pcObjects) = 0; - virtual HRESULT STDMETHODCALLTYPE GetAt( - /* [in] */ UINT uiIndex, - /* [in] */ __RPC__in REFIID riid, - /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0; + virtual HRESULT STDMETHODCALLTYPE GetAt( + /* [in] */ UINT uiIndex, + /* [in] */ __RPC__in REFIID riid, + /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0; -}; -#endif /* __IObjectArray_INTERFACE_DEFINED__ */ + }; +#endif /* __IObjectArray_INTERFACE_DEFINED__ */ #ifndef __IObjectCollection_INTERFACE_DEFINED__ #define __IObjectCollection_INTERFACE_DEFINED__ -/* interface IObjectCollection */ -/* [unique][object][uuid] */ + /* interface IObjectCollection */ + /* [unique][object][uuid] */ -EXTERN_C const IID IID_IObjectCollection; + EXTERN_C const IID IID_IObjectCollection; -MIDL_INTERFACE("5632b1a4-e38a-400a-928a-d4cd63230295") -IObjectCollection : public IObjectArray -{ + MIDL_INTERFACE("5632b1a4-e38a-400a-928a-d4cd63230295") +IObjectCollection : public IObjectArray { public: - virtual HRESULT STDMETHODCALLTYPE AddObject( - /* [in] */ __RPC__in_opt IUnknown *punk) = 0; + virtual HRESULT STDMETHODCALLTYPE AddObject( + /* [in] */ __RPC__in_opt IUnknown* punk) = 0; - virtual HRESULT STDMETHODCALLTYPE AddFromArray( - /* [in] */ __RPC__in_opt IObjectArray *poaSource) = 0; + virtual HRESULT STDMETHODCALLTYPE AddFromArray( + /* [in] */ __RPC__in_opt IObjectArray* poaSource) = 0; - virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt( - /* [in] */ UINT uiIndex) = 0; + virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt( + /* [in] */ UINT uiIndex) = 0; - virtual HRESULT STDMETHODCALLTYPE Clear( void) = 0; + virtual HRESULT STDMETHODCALLTYPE Clear(void) = 0; -}; -#endif /* __IObjectCollection_INTERFACE_DEFINED__ */ + }; +#endif /* __IObjectCollection_INTERFACE_DEFINED__ */ -/* Additional Prototypes for ALL interfaces */ -/* end of Additional Prototypes */ + /* Additional Prototypes for ALL interfaces */ + /* end of Additional Prototypes */ #ifdef __cplusplus } @@ -119,46 +117,45 @@ typedef interface ICustomDestinationList ICustomDestinationList; /* [unique][object][uuid] */ typedef /* [v1_enum] */ -enum KNOWNDESTCATEGORY -{ KDC_FREQUENT = 1, - KDC_RECENT = ( KDC_FREQUENT + 1 ) -} KNOWNDESTCATEGORY; +enum KNOWNDESTCATEGORY { + KDC_FREQUENT = 1, + KDC_RECENT = (KDC_FREQUENT + 1) +} KNOWNDESTCATEGORY; EXTERN_C const IID IID_ICustomDestinationList; MIDL_INTERFACE("6332debf-87b5-4670-90c0-5e57b408a49e") -ICustomDestinationList : public IUnknown -{ - public: +ICustomDestinationList : public IUnknown { +public: virtual HRESULT STDMETHODCALLTYPE SetAppID( - /* [string][in] */ __RPC__in_string LPCWSTR pszAppID) = 0; + /* [string][in] */ __RPC__in_string LPCWSTR pszAppID) = 0; virtual HRESULT STDMETHODCALLTYPE BeginList( - /* [out] */ __RPC__out UINT *pcMinSlots, - /* [in] */ __RPC__in REFIID riid, - /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0; + /* [out] */ __RPC__out UINT* pcMinSlots, + /* [in] */ __RPC__in REFIID riid, + /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0; virtual HRESULT STDMETHODCALLTYPE AppendCategory( - /* [string][in] */ __RPC__in_string LPCWSTR pszCategory, - /* [in] */ __RPC__in_opt IObjectArray *poa) = 0; + /* [string][in] */ __RPC__in_string LPCWSTR pszCategory, + /* [in] */ __RPC__in_opt IObjectArray* poa) = 0; virtual HRESULT STDMETHODCALLTYPE AppendKnownCategory( - /* [in] */ KNOWNDESTCATEGORY category) = 0; + /* [in] */ KNOWNDESTCATEGORY category) = 0; virtual HRESULT STDMETHODCALLTYPE AddUserTasks( - /* [in] */ __RPC__in_opt IObjectArray *poa) = 0; + /* [in] */ __RPC__in_opt IObjectArray* poa) = 0; - virtual HRESULT STDMETHODCALLTYPE CommitList( void) = 0; + virtual HRESULT STDMETHODCALLTYPE CommitList(void) = 0; virtual HRESULT STDMETHODCALLTYPE GetRemovedDestinations( - /* [in] */ __RPC__in REFIID riid, - /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0; + /* [in] */ __RPC__in REFIID riid, + /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0; virtual HRESULT STDMETHODCALLTYPE DeleteList( - /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszAppID) = 0; + /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszAppID) = 0; - virtual HRESULT STDMETHODCALLTYPE AbortList( void) = 0; + virtual HRESULT STDMETHODCALLTYPE AbortList(void) = 0; }; /* @@ -192,51 +189,50 @@ class DECLSPEC_UUID("77f10cf0-3db5-4966-b520-b7c54fd35ed6") */ #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ extern "C++" { \ - inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \ - inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \ - inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \ - inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \ - inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((int)a)); } \ - inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) ^ ((int)b)); } \ - inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \ + inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \ + inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \ + inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \ + inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \ + inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((int)a)); } \ + inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) ^ ((int)b)); } \ + inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \ } #ifdef MIDL_PASS -typedef IUnknown *HIMAGELIST; +typedef IUnknown* HIMAGELIST; #endif typedef /* [v1_enum] */ -enum THUMBBUTTONFLAGS -{ THBF_ENABLED = 0, - THBF_DISABLED = 0x1, - THBF_DISMISSONCLICK = 0x2, - THBF_NOBACKGROUND = 0x4, - THBF_HIDDEN = 0x8, - THBF_NONINTERACTIVE = 0x10 -} THUMBBUTTONFLAGS; +enum THUMBBUTTONFLAGS { + THBF_ENABLED = 0, + THBF_DISABLED = 0x1, + THBF_DISMISSONCLICK = 0x2, + THBF_NOBACKGROUND = 0x4, + THBF_HIDDEN = 0x8, + THBF_NONINTERACTIVE = 0x10 +} THUMBBUTTONFLAGS; DEFINE_ENUM_FLAG_OPERATORS(THUMBBUTTONFLAGS) typedef /* [v1_enum] */ -enum THUMBBUTTONMASK -{ THB_BITMAP = 0x1, - THB_ICON = 0x2, - THB_TOOLTIP = 0x4, - THB_FLAGS = 0x8 -} THUMBBUTTONMASK; +enum THUMBBUTTONMASK { + THB_BITMAP = 0x1, + THB_ICON = 0x2, + THB_TOOLTIP = 0x4, + THB_FLAGS = 0x8 +} THUMBBUTTONMASK; DEFINE_ENUM_FLAG_OPERATORS(THUMBBUTTONMASK) #include -typedef struct THUMBBUTTON -{ +typedef struct THUMBBUTTON { THUMBBUTTONMASK dwMask; UINT iId; UINT iBitmap; HICON hIcon; WCHAR szTip[ 260 ]; THUMBBUTTONFLAGS dwFlags; -} THUMBBUTTON; +} THUMBBUTTON; -typedef struct THUMBBUTTON *LPTHUMBBUTTON; +typedef struct THUMBBUTTON* LPTHUMBBUTTON; #include #define THBN_CLICKED 0x1800 @@ -249,13 +245,13 @@ extern RPC_IF_HANDLE __MIDL_itf_shobjidl_0000_0093_v0_0_s_ifspec; /* [object][uuid] */ typedef /* [v1_enum] */ -enum TBPFLAG -{ TBPF_NOPROGRESS = 0, - TBPF_INDETERMINATE = 0x1, - TBPF_NORMAL = 0x2, - TBPF_ERROR = 0x4, - TBPF_PAUSED = 0x8 -} TBPFLAG; +enum TBPFLAG { + TBPF_NOPROGRESS = 0, + TBPF_INDETERMINATE = 0x1, + TBPF_NORMAL = 0x2, + TBPF_ERROR = 0x4, + TBPF_PAUSED = 0x8 +} TBPFLAG; DEFINE_ENUM_FLAG_OPERATORS(TBPFLAG) @@ -263,60 +259,59 @@ EXTERN_C const IID IID_ITaskbarList3; MIDL_INTERFACE("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf") -ITaskbarList3 : public ITaskbarList2 -{ - public: +ITaskbarList3 : public ITaskbarList2 { +public: virtual HRESULT STDMETHODCALLTYPE SetProgressValue( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ ULONGLONG ullCompleted, - /* [in] */ ULONGLONG ullTotal) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ ULONGLONG ullCompleted, + /* [in] */ ULONGLONG ullTotal) = 0; virtual HRESULT STDMETHODCALLTYPE SetProgressState( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ TBPFLAG tbpFlags) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ TBPFLAG tbpFlags) = 0; virtual HRESULT STDMETHODCALLTYPE RegisterTab( - /* [in] */ __RPC__in HWND hwndTab, - /* [in] */ __RPC__in HWND hwndMDI) = 0; + /* [in] */ __RPC__in HWND hwndTab, + /* [in] */ __RPC__in HWND hwndMDI) = 0; virtual HRESULT STDMETHODCALLTYPE UnregisterTab( - /* [in] */ __RPC__in HWND hwndTab) = 0; + /* [in] */ __RPC__in HWND hwndTab) = 0; virtual HRESULT STDMETHODCALLTYPE SetTabOrder( - /* [in] */ __RPC__in HWND hwndTab, - /* [in] */ __RPC__in HWND hwndInsertBefore) = 0; + /* [in] */ __RPC__in HWND hwndTab, + /* [in] */ __RPC__in HWND hwndInsertBefore) = 0; virtual HRESULT STDMETHODCALLTYPE SetTabActive( - /* [in] */ __RPC__in HWND hwndTab, - /* [in] */ __RPC__in HWND hwndMDI, - /* [in] */ DWORD dwReserved) = 0; + /* [in] */ __RPC__in HWND hwndTab, + /* [in] */ __RPC__in HWND hwndMDI, + /* [in] */ DWORD dwReserved) = 0; virtual HRESULT STDMETHODCALLTYPE ThumbBarAddButtons( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ UINT cButtons, - /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ UINT cButtons, + /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; virtual HRESULT STDMETHODCALLTYPE ThumbBarUpdateButtons( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ UINT cButtons, - /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ UINT cButtons, + /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; virtual HRESULT STDMETHODCALLTYPE ThumbBarSetImageList( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ __RPC__in_opt HIMAGELIST himl) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ __RPC__in_opt HIMAGELIST himl) = 0; virtual HRESULT STDMETHODCALLTYPE SetOverlayIcon( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ __RPC__in HICON hIcon, - /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszDescription) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ __RPC__in HICON hIcon, + /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszDescription) = 0; virtual HRESULT STDMETHODCALLTYPE SetThumbnailTooltip( - /* [in] */ __RPC__in HWND hwnd, - /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszTip) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszTip) = 0; virtual HRESULT STDMETHODCALLTYPE SetThumbnailClip( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ __RPC__in RECT *prcClip) = 0; + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ __RPC__in RECT* prcClip) = 0; }; #endif //_MSC_VER >= 1500 && _MSC_VER < 1600 diff --git a/src/3rdparty/qtlocalpeer.cpp b/src/3rdparty/qtlocalpeer.cpp index 2597cba7a..2851faebd 100644 --- a/src/3rdparty/qtlocalpeer.cpp +++ b/src/3rdparty/qtlocalpeer.cpp @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ @@ -52,14 +52,15 @@ #if defined(Q_OS_WIN) #include #include -typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); +typedef BOOL(WINAPI* PProcessIdToSessionId)(DWORD, DWORD*); static PProcessIdToSessionId pProcessIdToSessionId = 0; #endif #if defined(Q_OS_UNIX) #include #endif -namespace QtLP_Private { +namespace QtLP_Private +{ #include "qtlockedfile.cpp" #if defined(Q_OS_WIN) #include "qtlockedfile_win.cpp" @@ -115,22 +116,25 @@ QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) bool QtLocalPeer::isClient() { - if (lockFile.isLocked()) + if (lockFile.isLocked()) { return false; + } - if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) + if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) { return true; + } bool res = server->listen(socketName); #if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) // ### Workaround if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { - QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); + QFile::remove(QDir::cleanPath(QDir::tempPath()) + QLatin1Char('/') + socketName); res = server->listen(socketName); } #endif - if (!res) + if (!res) { qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); + } QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); return false; } @@ -138,17 +142,19 @@ bool QtLocalPeer::isClient() bool QtLocalPeer::sendMessage(const QString &message, int timeout) { - if (!isClient()) + if (!isClient()) { return false; + } QLocalSocket socket; bool connOk = false; - for(int i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { // Try twice, in case the other instance is just starting up socket.connectToServer(socketName); - connOk = socket.waitForConnected(timeout/2); - if (connOk || i) + connOk = socket.waitForConnected(timeout / 2); + if (connOk || i) { break; + } int ms = 250; #if defined(Q_OS_WIN) Sleep(DWORD(ms)); @@ -157,8 +163,9 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout) nanosleep(&ts, NULL); #endif } - if (!connOk) + if (!connOk) { return false; + } QByteArray uMsg(message.toUtf8()); QDataStream ds(&socket); @@ -173,11 +180,13 @@ bool QtLocalPeer::sendMessage(const QString &message, int timeout) void QtLocalPeer::receiveConnection() { QLocalSocket* socket = server->nextPendingConnection(); - if (!socket) + if (!socket) { return; + } - while (socket->bytesAvailable() < (int)sizeof(quint32)) + while (socket->bytesAvailable() < (int)sizeof(quint32)) { socket->waitForReadyRead(); + } QDataStream ds(socket); QByteArray uMsg; quint32 remaining; @@ -189,7 +198,8 @@ void QtLocalPeer::receiveConnection() got = ds.readRawData(uMsgBuf, remaining); remaining -= got; uMsgBuf += got; - } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); + } + while (remaining && got >= 0 && socket->waitForReadyRead(2000)); if (got < 0) { qWarning("QtLocalPeer: Message reception failed %s", qPrintable(socket->errorString())); delete socket; diff --git a/src/3rdparty/qtlocalpeer.h b/src/3rdparty/qtlocalpeer.h index 8a54a9b5e..ed8715f07 100644 --- a/src/3rdparty/qtlocalpeer.h +++ b/src/3rdparty/qtlocalpeer.h @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ @@ -49,7 +49,8 @@ #include #include -namespace QtLP_Private { +namespace QtLP_Private +{ #include "qtlockedfile.h" } @@ -58,11 +59,11 @@ class QtLocalPeer : public QObject Q_OBJECT public: - QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); + QtLocalPeer(QObject* parent = 0, const QString &appId = QString()); bool isClient(); bool sendMessage(const QString &message, int timeout); QString applicationId() const - { return id; } + { return id; } Q_SIGNALS: void messageReceived(const QString &message); diff --git a/src/3rdparty/qtlockedfile.cpp b/src/3rdparty/qtlockedfile.cpp index 2cf080584..af0586712 100644 --- a/src/3rdparty/qtlockedfile.cpp +++ b/src/3rdparty/qtlockedfile.cpp @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ #include "qtlockedfile.h" diff --git a/src/3rdparty/qtlockedfile.h b/src/3rdparty/qtlockedfile.h index 1d3b918ec..89b4e3358 100644 --- a/src/3rdparty/qtlockedfile.h +++ b/src/3rdparty/qtlockedfile.h @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ #ifndef QTLOCKEDFILE_H diff --git a/src/3rdparty/qtlockedfile_unix.cpp b/src/3rdparty/qtlockedfile_unix.cpp index 2881bdd2c..888c47f4b 100644 --- a/src/3rdparty/qtlockedfile_unix.cpp +++ b/src/3rdparty/qtlockedfile_unix.cpp @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ #include @@ -57,15 +57,18 @@ bool QtLockedFile::lock(LockMode mode, bool block) qWarning("QtLockedFile::lock(): file is not opened"); return false; } - - if (mode == NoLock) - return unlock(); - - if (mode == m_lock_mode) - return true; - if (m_lock_mode != NoLock) + if (mode == NoLock) { + return unlock(); + } + + if (mode == m_lock_mode) { + return true; + } + + if (m_lock_mode != NoLock) { unlock(); + } struct flock fl; fl.l_whence = SEEK_SET; @@ -74,14 +77,15 @@ bool QtLockedFile::lock(LockMode mode, bool block) fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; int cmd = block ? F_SETLKW : F_SETLK; int ret = fcntl(handle(), cmd, &fl); - + if (ret == -1) { - if (errno != EINTR && errno != EAGAIN) + if (errno != EINTR && errno != EAGAIN) { qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); + } return false; } - + m_lock_mode = mode; return true; } @@ -94,8 +98,9 @@ bool QtLockedFile::unlock() return false; } - if (!isLocked()) + if (!isLocked()) { return true; + } struct flock fl; fl.l_whence = SEEK_SET; @@ -103,19 +108,20 @@ bool QtLockedFile::unlock() fl.l_len = 0; fl.l_type = F_UNLCK; int ret = fcntl(handle(), F_SETLKW, &fl); - + if (ret == -1) { qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); return false; } - + m_lock_mode = NoLock; return true; } QtLockedFile::~QtLockedFile() { - if (isOpen()) + if (isOpen()) { unlock(); + } } diff --git a/src/3rdparty/qtlockedfile_win.cpp b/src/3rdparty/qtlockedfile_win.cpp index d4bf9e141..bba7c7c5a 100644 --- a/src/3rdparty/qtlockedfile_win.cpp +++ b/src/3rdparty/qtlockedfile_win.cpp @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ #include "qtlockedfile.h" @@ -60,13 +60,14 @@ Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) + fi.absoluteFilePath().toLower(); } QString mname(mutexname); - if (idx >= 0) + if (idx >= 0) { mname += QString::number(idx); + } Qt::HANDLE mutex; if (doCreate) { QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, - { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); + { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); }); if (!mutex) { qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); return 0; @@ -74,10 +75,11 @@ Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) } else { QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, - { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); + { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); }); if (!mutex) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) + if (GetLastError() != ERROR_FILE_NOT_FOUND) { qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); + } return 0; } } @@ -110,27 +112,33 @@ bool QtLockedFile::lock(LockMode mode, bool block) return false; } - if (mode == NoLock) + if (mode == NoLock) { return unlock(); + } - if (mode == m_lock_mode) + if (mode == m_lock_mode) { return true; + } - if (m_lock_mode != NoLock) + if (m_lock_mode != NoLock) { unlock(); + } - if (!wmutex && !(wmutex = getMutexHandle(-1, true))) + if (!wmutex && !(wmutex = getMutexHandle(-1, true))) { return false; + } - if (!waitMutex(wmutex, block)) + if (!waitMutex(wmutex, block)) { return false; + } if (mode == ReadLock) { int idx = 0; for (; idx < MAX_READERS; idx++) { rmutex = getMutexHandle(idx, false); - if (!rmutex || waitMutex(rmutex, false)) + if (!rmutex || waitMutex(rmutex, false)) { break; + } CloseHandle(rmutex); } bool ok = true; @@ -141,30 +149,34 @@ bool QtLockedFile::lock(LockMode mode, bool block) } else if (!rmutex) { rmutex = getMutexHandle(idx, true); - if (!rmutex || !waitMutex(rmutex, false)) + if (!rmutex || !waitMutex(rmutex, false)) { ok = false; + } } if (!ok && rmutex) { CloseHandle(rmutex); rmutex = 0; } ReleaseMutex(wmutex); - if (!ok) + if (!ok) { return false; + } } else { Q_ASSERT(rmutexes.isEmpty()); for (int i = 0; i < MAX_READERS; i++) { Qt::HANDLE mutex = getMutexHandle(i, false); - if (mutex) + if (mutex) { rmutexes.append(mutex); + } } if (rmutexes.size()) { DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), TRUE, block ? INFINITE : 0); if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { - if (res != WAIT_TIMEOUT) + if (res != WAIT_TIMEOUT) { qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); + } m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky unlock(); return false; @@ -183,8 +195,9 @@ bool QtLockedFile::unlock() return false; } - if (!isLocked()) + if (!isLocked()) { return true; + } if (m_lock_mode == ReadLock) { ReleaseMutex(rmutex); @@ -206,8 +219,10 @@ bool QtLockedFile::unlock() QtLockedFile::~QtLockedFile() { - if (isOpen()) + if (isOpen()) { unlock(); - if (wmutex) + } + if (wmutex) { CloseHandle(wmutex); + } } diff --git a/src/3rdparty/qtsingleapplication.cpp b/src/3rdparty/qtsingleapplication.cpp index 46204335b..d666ba93f 100644 --- a/src/3rdparty/qtsingleapplication.cpp +++ b/src/3rdparty/qtsingleapplication.cpp @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ @@ -143,7 +143,7 @@ void QtSingleApplication::sysInit(const QString &appId) { actWin = 0; peer = new QtLocalPeer(this, appId); - connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); + connect(peer, SIGNAL(messageReceived(const QString &)), SIGNAL(messageReceived(const QString &))); } @@ -157,7 +157,7 @@ void QtSingleApplication::sysInit(const QString &appId) QtSingleCoreApplication instead. */ -QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) +QtSingleApplication::QtSingleApplication(int &argc, char** argv, bool GUIenabled) : QApplication(argc, argv, GUIenabled) { sysInit(); @@ -170,7 +170,7 @@ QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled QAppliation constructor. */ -QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) +QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char** argv) : QApplication(argc, argv) { sysInit(appId); @@ -182,7 +182,7 @@ QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char * will be QCoreApplication::applicationFilePath(). \a argc, \a argv, and \a type are passed on to the QAppliation constructor. */ -QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) +QtSingleApplication::QtSingleApplication(int &argc, char** argv, Type type) : QApplication(argc, argv, type) { sysInit(); @@ -209,7 +209,7 @@ QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HA argv, \a visual, and \a cmap are passed on to the QApplication constructor. */ -QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) +QtSingleApplication::QtSingleApplication(Display* dpy, int &argc, char** argv, Qt::HANDLE visual, Qt::HANDLE cmap) : QApplication(dpy, argc, argv, visual, cmap) { sysInit(); @@ -222,7 +222,7 @@ QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Q argv, \a visual, and \a cmap are passed on to the QApplication constructor. */ -QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) +QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char** argv, Qt::HANDLE visual, Qt::HANDLE cmap) : QApplication(dpy, argc, argv, visual, cmap) { sysInit(appId); @@ -291,10 +291,12 @@ QString QtSingleApplication::id() const void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) { actWin = aw; - if (activateOnMessage) - connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); - else - disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); + if (activateOnMessage) { + connect(peer, SIGNAL(messageReceived(const QString &)), this, SLOT(activateWindow())); + } + else { + disconnect(peer, SIGNAL(messageReceived(const QString &)), this, SLOT(activateWindow())); + } } diff --git a/src/3rdparty/qtsingleapplication.h b/src/3rdparty/qtsingleapplication.h index 5df916561..f8a5fd86f 100644 --- a/src/3rdparty/qtsingleapplication.h +++ b/src/3rdparty/qtsingleapplication.h @@ -1,17 +1,17 @@ /**************************************************************************** -** +** ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) -** +** ** This file is part of a Qt Solutions component. ** -** Commercial Usage +** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Solutions Commercial License Agreement provided ** with the Software or, alternatively, in accordance with the terms ** contained in a written agreement between you and Nokia. -** +** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software @@ -19,29 +19,29 @@ ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** +** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this ** package. -** -** GNU General Public License Usage +** +** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. -** +** ** Please note Third Party Software included with Qt Solutions may impose ** additional restrictions and it is the user's responsibility to ensure ** that they have met the licensing requirements of the GPL, LGPL, or Qt ** Solutions Commercial license and the relevant license of the Third ** Party Software they are using. -** +** ** If you are unsure which license is appropriate for your use, please ** contact Nokia at qt-info@nokia.com. -** +** ****************************************************************************/ @@ -70,13 +70,13 @@ class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication Q_OBJECT public: - QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); - QtSingleApplication(const QString &id, int &argc, char **argv); - QtSingleApplication(int &argc, char **argv, Type type); + QtSingleApplication(int &argc, char** argv, bool GUIenabled = true); + QtSingleApplication(const QString &id, int &argc, char** argv); + QtSingleApplication(int &argc, char** argv, Type type); #if defined(Q_WS_X11) QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); - QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); - QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); + QtSingleApplication(Display* dpy, int &argc, char** argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap = 0); + QtSingleApplication(Display* dpy, const QString &appId, int argc, char** argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); #endif bool isRunning(); @@ -87,7 +87,7 @@ public: // Obsolete: void initialize(bool dummy = true) - { isRunning(); Q_UNUSED(dummy) } + { isRunning(); Q_UNUSED(dummy) } public Q_SLOTS: bool sendMessage(const QString &message, int timeout = 5000); @@ -100,6 +100,6 @@ Q_SIGNALS: private: void sysInit(const QString &appId = QString()); - QtLocalPeer *peer; - QWidget *actWin; + QtLocalPeer* peer; + QWidget* actWin; }; diff --git a/src/3rdparty/qtwin.cpp b/src/3rdparty/qtwin.cpp index 7de0d3df9..c763a5f44 100644 --- a/src/3rdparty/qtwin.cpp +++ b/src/3rdparty/qtwin.cpp @@ -42,28 +42,27 @@ #define DWM_BB_TRANSITIONONMAXIMIZED 0x00000004 // fTransitionOnMaximized has been specified #define WM_DWMCOMPOSITIONCHANGED 0x031E // Composition changed window message -typedef struct _DWM_BLURBEHIND -{ +typedef struct _DWM_BLURBEHIND { DWORD dwFlags; BOOL fEnable; HRGN hRgnBlur; BOOL fTransitionOnMaximized; } DWM_BLURBEHIND, *PDWM_BLURBEHIND; -typedef struct _MARGINS -{ - int cxLeftWidth; - int cxRightWidth; - int cyTopHeight; - int cyBottomHeight; -} MARGINS, *PMARGINS; +//typedef struct _MARGINS +//{ +// int cxLeftWidth; +// int cxRightWidth; +// int cyTopHeight; +// int cyBottomHeight; +//} MARGINS, *PMARGINS; -typedef HRESULT (WINAPI *PtrDwmIsCompositionEnabled)(BOOL* pfEnabled); -typedef HRESULT (WINAPI *PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS* pMarInset); -typedef HRESULT (WINAPI *PtrDwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); -typedef HRESULT (WINAPI *PtrDwmGetColorizationColor)(DWORD *pcrColorization, BOOL *pfOpaqueBlend); +typedef HRESULT(WINAPI* PtrDwmIsCompositionEnabled)(BOOL* pfEnabled); +typedef HRESULT(WINAPI* PtrDwmExtendFrameIntoClientArea)(HWND hWnd, const MARGINS* pMarInset); +typedef HRESULT(WINAPI* PtrDwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); +typedef HRESULT(WINAPI* PtrDwmGetColorizationColor)(DWORD* pcrColorization, BOOL* pfOpaqueBlend); -static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled= 0; +static PtrDwmIsCompositionEnabled pDwmIsCompositionEnabled = 0; static PtrDwmEnableBlurBehindWindow pDwmEnableBlurBehindWindow = 0; static PtrDwmExtendFrameIntoClientArea pDwmExtendFrameIntoClientArea = 0; static PtrDwmGetColorizationColor pDwmGetColorizationColor = 0; @@ -77,10 +76,16 @@ static PtrDwmGetColorizationColor pDwmGetColorizationColor = 0; class WindowNotifier : public QWidget { public: - WindowNotifier() { winId(); } - void addWidget(QWidget *widget) { widgets.append(widget); } - void removeWidget(QWidget *widget) { widgets.removeAll(widget); } - bool winEvent(MSG *message, long *result); + WindowNotifier() { + winId(); + } + void addWidget(QWidget* widget) { + widgets.append(widget); + } + void removeWidget(QWidget* widget) { + widgets.removeAll(widget); + } + bool winEvent(MSG* message, long* result); private: QWidgetList widgets; @@ -90,7 +95,7 @@ static bool resolveLibs() { if (!pDwmIsCompositionEnabled) { QLibrary dwmLib(QString::fromAscii("dwmapi")); - pDwmIsCompositionEnabled =(PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); + pDwmIsCompositionEnabled = (PtrDwmIsCompositionEnabled)dwmLib.resolve("DwmIsCompositionEnabled"); pDwmExtendFrameIntoClientArea = (PtrDwmExtendFrameIntoClientArea)dwmLib.resolve("DwmExtendFrameIntoClientArea"); pDwmEnableBlurBehindWindow = (PtrDwmEnableBlurBehindWindow)dwmLib.resolve("DwmEnableBlurBehindWindow"); pDwmGetColorizationColor = (PtrDwmGetColorizationColor)dwmLib.resolve("DwmGetColorizationColor"); @@ -133,8 +138,9 @@ bool QtWin::isCompositionEnabled() HRESULT hr = S_OK; BOOL isEnabled = false; hr = pDwmIsCompositionEnabled(&isEnabled); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { return isEnabled; + } } #endif return false; @@ -145,7 +151,7 @@ bool QtWin::isCompositionEnabled() * * \a enable tells if the blur should be enabled or not */ -bool QtWin::enableBlurBehindWindow(QWidget *widget, bool enable) +bool QtWin::enableBlurBehindWindow(QWidget* widget, bool enable) { Q_UNUSED(enable); Q_UNUSED(widget); @@ -182,7 +188,7 @@ bool QtWin::enableBlurBehindWindow(QWidget *widget, bool enable) * * \a enable tells if the blur should be enabled or not */ -bool QtWin::extendFrameIntoClientArea(QWidget *widget, int left, int top, int right, int bottom) +bool QtWin::extendFrameIntoClientArea(QWidget* widget, int left, int top, int right, int bottom) { Q_ASSERT(widget); @@ -225,25 +231,27 @@ QColor QtWin::colorizationColor() QLibrary dwmLib(QString::fromAscii("dwmapi")); HRESULT hr = S_OK; hr = pDwmGetColorizationColor(&color, &opaque); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) { resultColor = QColor(color); + } } #endif return resultColor; } #ifdef Q_WS_WIN -WindowNotifier *QtWin::windowNotifier() +WindowNotifier* QtWin::windowNotifier() { - static WindowNotifier *windowNotifierInstance = 0; - if (!windowNotifierInstance) + static WindowNotifier* windowNotifierInstance = 0; + if (!windowNotifierInstance) { windowNotifierInstance = new WindowNotifier; + } return windowNotifierInstance; } /* Notify all enabled windows that the DWM state changed */ -bool WindowNotifier::winEvent(MSG *message, long *result) +bool WindowNotifier::winEvent(MSG* message, long* result) { if (message && message->message == WM_DWMCOMPOSITIONCHANGED) { bool compositionEnabled = QtWin::isCompositionEnabled(); @@ -259,8 +267,9 @@ bool WindowNotifier::winEvent(MSG *message, long *result) #ifdef W7API IShellLink* QtWin::CreateShellLink(const QString &title, const QString &description, - const QString &app_path, const QString &app_args, - const QString &icon_path, int app_index) { + const QString &app_path, const QString &app_args, + const QString &icon_path, int app_index) +{ const wchar_t* _title = reinterpret_cast(title.utf16()); const wchar_t* _description = reinterpret_cast(description.utf16()); @@ -273,8 +282,8 @@ IShellLink* QtWin::CreateShellLink(const QString &title, const QString &descript bool is_not_separator = (app_path.length() > 0); HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, - reinterpret_cast (&(shell_link))); - if(SUCCEEDED(hr)) { + reinterpret_cast(&(shell_link))); + if (SUCCEEDED(hr)) { if (is_not_separator) { shell_link->SetPath(_app_path); shell_link->SetArguments(_app_args); @@ -282,7 +291,7 @@ IShellLink* QtWin::CreateShellLink(const QString &title, const QString &descript shell_link->SetDescription(_description); } - hr = shell_link->QueryInterface(IID_IPropertyStore, reinterpret_cast (&(prop_store))); + hr = shell_link->QueryInterface(IID_IPropertyStore, reinterpret_cast(&(prop_store))); if (SUCCEEDED(hr)) { PROPVARIANT pv; @@ -292,7 +301,8 @@ IShellLink* QtWin::CreateShellLink(const QString &title, const QString &descript if (SUCCEEDED(hr)) { hr = prop_store->SetValue(PKEY_Title, pv); } - } else { + } + else { hr = InitPropVariantFromBoolean(TRUE, &pv); if (SUCCEEDED(hr)) { @@ -314,20 +324,21 @@ void QtWin::populateFrequentSites(IObjectCollection* collection, const QString & { HistoryModel* historyModel = mApp->history(); QList mostList = historyModel->mostVisited(6); - foreach (HistoryModel::HistoryEntry entry, mostList) - collection->AddObject(CreateShellLink(entry.title, entry.url.toString(), appPath, " "+entry.url.toEncoded(), appPath, 1)); + foreach(HistoryModel::HistoryEntry entry, mostList) + collection->AddObject(CreateShellLink(entry.title, entry.url.toString(), appPath, " " + entry.url.toEncoded(), appPath, 1)); collection->AddObject(CreateShellLink("", "", "", "", "", 0)); //Spacer } -void QtWin::AddTasksToList(ICustomDestinationList* destinationList) { +void QtWin::AddTasksToList(ICustomDestinationList* destinationList) +{ IObjectArray* object_array; IObjectCollection* obj_collection; CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, - CLSCTX_INPROC, IID_IObjectCollection, reinterpret_cast (&(obj_collection))); + CLSCTX_INPROC, IID_IObjectCollection, reinterpret_cast(&(obj_collection))); - obj_collection->QueryInterface(IID_IObjectArray, reinterpret_cast (&(object_array))); + obj_collection->QueryInterface(IID_IObjectArray, reinterpret_cast(&(object_array))); QString icons_source = qApp->applicationFilePath(); QString app_path = qApp->applicationFilePath(); @@ -335,16 +346,16 @@ void QtWin::AddTasksToList(ICustomDestinationList* destinationList) { populateFrequentSites(obj_collection, icons_source); obj_collection->AddObject(CreateShellLink(tr("Open new tab"), tr("Opens a new tab if browser is running"), - app_path, "--new-tab", - icons_source, 0)); + app_path, "--new-tab", + icons_source, 0)); obj_collection->AddObject(CreateShellLink(tr("Open new window"), tr("Opens a new window if browser is running"), - app_path, "--new-window", - icons_source, 0)); + app_path, "--new-window", + icons_source, 0)); obj_collection->AddObject(CreateShellLink(tr("Open download manager"), tr("Opens a download manager if browser is running"), - app_path, "--download-manager", - icons_source, 0)); + app_path, "--download-manager", + icons_source, 0)); destinationList->AddUserTasks(object_array); @@ -354,10 +365,12 @@ void QtWin::AddTasksToList(ICustomDestinationList* destinationList) { #endif //W7API #endif //Q_WS_WIN -void QtWin::setupJumpList() { +void QtWin::setupJumpList() +{ #ifdef W7API - if (!isRunningWindows7()) + if (!isRunningWindows7()) { return; + } UINT max_count = 0; IObjectArray* objectArray; @@ -365,10 +378,10 @@ void QtWin::setupJumpList() { //create the custom jump list object CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, IID_ICustomDestinationList, - reinterpret_cast (&(destinationList))); + reinterpret_cast(&(destinationList))); //initialize list - destinationList->BeginList(&max_count, IID_IObjectArray, reinterpret_cast (&(objectArray))); + destinationList->BeginList(&max_count, IID_IObjectArray, reinterpret_cast(&(objectArray))); AddTasksToList(destinationList); //commit list diff --git a/src/3rdparty/qtwin.h b/src/3rdparty/qtwin.h index 870ac5cb8..ab1e90d5c 100644 --- a/src/3rdparty/qtwin.h +++ b/src/3rdparty/qtwin.h @@ -51,8 +51,8 @@ class QtWin : public QObject Q_OBJECT public: static bool isRunningWindows7(); - static bool enableBlurBehindWindow(QWidget *widget, bool enable = true); - static bool extendFrameIntoClientArea(QWidget *widget, + static bool enableBlurBehindWindow(QWidget* widget, bool enable = true); + static bool extendFrameIntoClientArea(QWidget* widget, int left = -1, int top = -1, int right = -1, int bottom = -1); static bool isCompositionEnabled(); @@ -62,7 +62,7 @@ public slots: static void setupJumpList(); private: - static WindowNotifier *windowNotifier(); + static WindowNotifier* windowNotifier(); #ifdef W7API static void populateFrequentSites(IObjectCollection* collection, const QString &appPath); static void AddTasksToList(ICustomDestinationList* destinationList); diff --git a/src/3rdparty/squeezelabelv1.cpp b/src/3rdparty/squeezelabelv1.cpp index 37e932449..8d2c2ef31 100644 --- a/src/3rdparty/squeezelabelv1.cpp +++ b/src/3rdparty/squeezelabelv1.cpp @@ -1,11 +1,11 @@ #include "squeezelabelv1.h" -SqueezeLabelV1::SqueezeLabelV1(QWidget *parent) +SqueezeLabelV1::SqueezeLabelV1(QWidget* parent) : QLabel(parent) { } -void SqueezeLabelV1::paintEvent(QPaintEvent *event) +void SqueezeLabelV1::paintEvent(QPaintEvent* event) { if (m_SqueezedTextCache != text()) { m_SqueezedTextCache = text(); diff --git a/src/3rdparty/squeezelabelv1.h b/src/3rdparty/squeezelabelv1.h index 47be9d5fc..4b7f089e6 100644 --- a/src/3rdparty/squeezelabelv1.h +++ b/src/3rdparty/squeezelabelv1.h @@ -40,10 +40,10 @@ class SqueezeLabelV1 : public QLabel Q_OBJECT public: - SqueezeLabelV1(QWidget *parent = 0); + SqueezeLabelV1(QWidget* parent = 0); protected: - void paintEvent(QPaintEvent *event); + void paintEvent(QPaintEvent* event); private: QString m_SqueezedTextCache; diff --git a/src/3rdparty/squeezelabelv2.cpp b/src/3rdparty/squeezelabelv2.cpp index 66c9e09a7..e6c8a0f13 100644 --- a/src/3rdparty/squeezelabelv2.cpp +++ b/src/3rdparty/squeezelabelv2.cpp @@ -1,6 +1,6 @@ #include "squeezelabelv2.h" -SqueezeLabelV2::SqueezeLabelV2(QWidget *parent) +SqueezeLabelV2::SqueezeLabelV2(QWidget* parent) : QLabel(parent) { } @@ -24,7 +24,7 @@ QString SqueezeLabelV2::originalText() return m_originalText; } -void SqueezeLabelV2::resizeEvent(QResizeEvent *event) +void SqueezeLabelV2::resizeEvent(QResizeEvent* event) { QLabel::resizeEvent(event); QFontMetrics fm = fontMetrics(); diff --git a/src/3rdparty/squeezelabelv2.h b/src/3rdparty/squeezelabelv2.h index 80359b4a0..7ad4ddb4f 100644 --- a/src/3rdparty/squeezelabelv2.h +++ b/src/3rdparty/squeezelabelv2.h @@ -40,14 +40,14 @@ class SqueezeLabelV2 : public QLabel Q_OBJECT public: - SqueezeLabelV2(QWidget *parent = 0); + SqueezeLabelV2(QWidget* parent = 0); SqueezeLabelV2(const QString &string); QString originalText(); void setText(const QString &txt); protected: - void resizeEvent(QResizeEvent *event); + void resizeEvent(QResizeEvent* event); private: QString m_SqueezedTextCache; diff --git a/src/3rdparty/stylehelper.cpp b/src/3rdparty/stylehelper.cpp index 84035f4cd..99d9fd8e8 100644 --- a/src/3rdparty/stylehelper.cpp +++ b/src/3rdparty/stylehelper.cpp @@ -45,7 +45,8 @@ static int clamp(float x) return val < 0 ? 0 : val; } -namespace Utils { +namespace Utils +{ qreal StyleHelper::sidebarFontSize() { @@ -58,10 +59,12 @@ qreal StyleHelper::sidebarFontSize() QColor StyleHelper::panelTextColor(bool lightColored) { - if (!lightColored) + if (!lightColored) { return Qt::white; - else + } + else { return Qt::black; + } } // Invalid by default, setBaseColor needs to be called at least once @@ -70,10 +73,12 @@ QColor StyleHelper::m_requestedBaseColor; QColor StyleHelper::baseColor(bool lightColored) { - if (!lightColored) + if (!lightColored) { return m_baseColor; - else + } + else { return m_baseColor.lighter(230); + } } QColor StyleHelper::highlightColor(bool lightColored) @@ -81,12 +86,12 @@ QColor StyleHelper::highlightColor(bool lightColored) QColor result = baseColor(lightColored); if (!lightColored) result.setHsv(result.hue(), - clamp(result.saturation()), - clamp(result.value() * 1.16)); + clamp(result.saturation()), + clamp(result.value() * 1.16)); else result.setHsv(result.hue(), - clamp(result.saturation()), - clamp(result.value() * 1.06)); + clamp(result.saturation()), + clamp(result.value() * 1.06)); return result; } @@ -122,12 +127,12 @@ void StyleHelper::setBaseColor(const QColor &newcolor) if (color.isValid() && color != m_baseColor) { m_baseColor = color; - foreach (QWidget *w, QApplication::topLevelWidgets()) - w->update(); + foreach(QWidget * w, QApplication::topLevelWidgets()) + w->update(); } } -static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRect &rect, bool lightColored) +static void verticalGradientHelper(QPainter* p, const QRect &spanRect, const QRect &rect, bool lightColored) { QColor highlight = StyleHelper::highlightColor(lightColored); QColor shadow = StyleHelper::shadowColor(lightColored); @@ -144,14 +149,14 @@ static void verticalGradientHelper(QPainter *p, const QRect &spanRect, const QRe p->drawLine(rect.topLeft(), rect.bottomLeft()); } -void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) +void StyleHelper::verticalGradient(QPainter* painter, const QRect &spanRect, const QRect &clipRect, bool lightColored) { if (StyleHelper::usePixmapCache()) { QString key; QColor keyColor = baseColor(lightColored); key.sprintf("mh_vertical %d %d %d %d %d", - spanRect.width(), spanRect.height(), clipRect.width(), - clipRect.height(), keyColor.rgb());; + spanRect.width(), spanRect.height(), clipRect.width(), + clipRect.height(), keyColor.rgb());; QPixmap pixmap; if (!QPixmapCache::find(key, pixmap)) { @@ -164,14 +169,15 @@ void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, con } painter->drawPixmap(clipRect.topLeft(), pixmap); - } else { + } + else { verticalGradientHelper(painter, spanRect, clipRect, lightColored); } } // Draws a cached pixmap with shadow void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, - QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) + QPainter* p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) { QPixmap cache; QString pixmapName = QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); @@ -184,9 +190,9 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter cachePainter(&cache); if (iconMode == QIcon::Disabled) { QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32); - for (int y=0; y #include -AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const QNetworkRequest &request, const AdBlockRule *rule, QObject *parent) +AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const QNetworkRequest &request, const AdBlockRule* rule, QObject* parent) : QNetworkReply(parent) { setOperation(QNetworkAccessManager::GetOperation); @@ -60,7 +60,7 @@ AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const QNetworkRequest &re QTimer::singleShot(0, this, SLOT(delayedFinished())); } -qint64 AdBlockBlockedNetworkReply::readData(char *data, qint64 maxSize) +qint64 AdBlockBlockedNetworkReply::readData(char* data, qint64 maxSize) { Q_UNUSED(data); Q_UNUSED(maxSize); diff --git a/src/adblock/adblockblockednetworkreply.h b/src/adblock/adblockblockednetworkreply.h index 50f1fb51c..fca458146 100644 --- a/src/adblock/adblockblockednetworkreply.h +++ b/src/adblock/adblockblockednetworkreply.h @@ -54,11 +54,11 @@ class AdBlockBlockedNetworkReply : public QNetworkReply Q_OBJECT public: - AdBlockBlockedNetworkReply(const QNetworkRequest &request, const AdBlockRule *rule, QObject *parent = 0); - void abort() {}; + AdBlockBlockedNetworkReply(const QNetworkRequest &request, const AdBlockRule* rule, QObject* parent = 0); + void abort() {} protected: - qint64 readData(char *data, qint64 maxSize); + qint64 readData(char* data, qint64 maxSize); private slots: void delayedFinished(); diff --git a/src/adblock/adblockdialog.cpp b/src/adblock/adblockdialog.cpp index 98522c4e5..596dbd781 100644 --- a/src/adblock/adblockdialog.cpp +++ b/src/adblock/adblockdialog.cpp @@ -47,7 +47,7 @@ #include "adblocksubscription.h" #include "mainapplication.h" -AdBlockDialog::AdBlockDialog(QWidget *parent) +AdBlockDialog::AdBlockDialog(QWidget* parent) : QDialog(parent) , m_itemChangingBlock(false) , m_manager(AdBlockManager::instance()) @@ -73,8 +73,9 @@ AdBlockDialog::AdBlockDialog(QWidget *parent) void AdBlockDialog::editRule() { QTreeWidgetItem* item = treeWidget->currentItem(); - if (!item || !(item->flags() & Qt::ItemIsEditable)) + if (!item || !(item->flags() & Qt::ItemIsEditable)) { return; + } item->setSelected(true); } @@ -82,8 +83,9 @@ void AdBlockDialog::editRule() void AdBlockDialog::deleteRule() { QTreeWidgetItem* item = treeWidget->currentItem(); - if (!item) + if (!item) { return; + } int offset = item->whatsThis(0).toInt(); m_manager->subscription()->removeRule(offset); @@ -103,7 +105,7 @@ void AdBlockDialog::customContextMenuRequested() void AdBlockDialog::firstRefresh() { refresh(); - connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*))); + connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*))); } void AdBlockDialog::refreshAfterUpdate() @@ -124,12 +126,12 @@ void AdBlockDialog::refresh() italicFont.setItalic(true); m_customRulesItem = new QTreeWidgetItem(treeWidget); - m_customRulesItem->setText(0,tr("Custom Rules")); + m_customRulesItem->setText(0, tr("Custom Rules")); m_customRulesItem->setFont(0, boldFont); treeWidget->addTopLevelItem(m_customRulesItem); m_easyListItem = new QTreeWidgetItem(treeWidget); - m_easyListItem->setText(0,"EasyList"); + m_easyListItem->setText(0, "EasyList"); m_easyListItem->setFont(0, boldFont); treeWidget->addTopLevelItem(m_easyListItem); @@ -137,31 +139,34 @@ void AdBlockDialog::refresh() QList allRules = m_manager->subscription()->allRules(); int index = 0; - foreach (const AdBlockRule rule, allRules) { + foreach(const AdBlockRule & rule, allRules) { index++; if (rule.filter().contains("*******- user custom filters")) { customRulesStarted = true; continue; } QTreeWidgetItem* item = new QTreeWidgetItem(customRulesStarted ? m_customRulesItem : m_easyListItem); - if (item->parent() == m_customRulesItem) + if (item->parent() == m_customRulesItem) { item->setFlags(item->flags() | Qt::ItemIsEditable); + } item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(0, (rule.filter().startsWith("!") ) ? Qt::Unchecked : Qt::Checked); + item->setCheckState(0, (rule.filter().startsWith("!")) ? Qt::Unchecked : Qt::Checked); item->setText(0, rule.filter()); - item->setWhatsThis(0, QString::number(index-1)); - if (rule.filter().startsWith("!")) + item->setWhatsThis(0, QString::number(index - 1)); + if (rule.filter().startsWith("!")) { item->setFont(0, italicFont); + } } treeWidget->expandAll(); treeWidget->setUpdatesEnabled(true); m_itemChangingBlock = false; } -void AdBlockDialog::itemChanged(QTreeWidgetItem *item) +void AdBlockDialog::itemChanged(QTreeWidgetItem* item) { - if (!item || m_itemChangingBlock) + if (!item || m_itemChangingBlock) { return; + } m_itemChangingBlock = true; @@ -175,7 +180,8 @@ void AdBlockDialog::itemChanged(QTreeWidgetItem *item) AdBlockRule rul(item->text(0)); m_manager->subscription()->replaceRule(rul, offset); - } else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) { //Enable rule + } + else if (item->checkState(0) == Qt::Checked && item->text(0).startsWith("!")) { //Enable rule int offset = item->whatsThis(0).toInt(); item->setFont(0, QFont()); QString newText = item->text(0).mid(1); @@ -184,7 +190,8 @@ void AdBlockDialog::itemChanged(QTreeWidgetItem *item) AdBlockRule rul(newText); m_manager->subscription()->replaceRule(rul, offset); - } else { //Custom rule has been changed + } + else { //Custom rule has been changed int offset = item->whatsThis(0).toInt(); AdBlockRule rul(item->text(0)); @@ -199,8 +206,9 @@ void AdBlockDialog::itemChanged(QTreeWidgetItem *item) void AdBlockDialog::addCustomRule() { QString newRule = QInputDialog::getText(this, tr("Add Custom Rule"), tr("Please write your rule here:")); - if (newRule.isEmpty()) + if (newRule.isEmpty()) { return; + } AdBlockSubscription* subscription = m_manager->subscription(); int offset = subscription->addRule(AdBlockRule(newRule)); diff --git a/src/adblock/adblockdialog.h b/src/adblock/adblockdialog.h index 5fc89323a..b576b8acb 100644 --- a/src/adblock/adblockdialog.h +++ b/src/adblock/adblockdialog.h @@ -68,7 +68,7 @@ class AdBlockDialog : public QDialog, public Ui_AdBlockDialog Q_OBJECT public: - AdBlockDialog(QWidget *parent = 0); + AdBlockDialog(QWidget* parent = 0); private slots: void itemChanged(QTreeWidgetItem* item); diff --git a/src/adblock/adblockicon.cpp b/src/adblock/adblockicon.cpp index c792f4151..bb080a046 100644 --- a/src/adblock/adblockicon.cpp +++ b/src/adblock/adblockicon.cpp @@ -21,8 +21,8 @@ #include "webpage.h" AdBlockIcon::AdBlockIcon(QupZilla* mainClass, QWidget* parent) - : ClickableLabel(parent) - , p_QupZilla(mainClass) + : ClickableLabel(parent) + , p_QupZilla(mainClass) { setMaximumHeight(16); setCursor(Qt::PointingHandCursor); @@ -39,11 +39,12 @@ void AdBlockIcon::showMenu(const QPoint &pos) menu.addAction(tr("Show AdBlock &Settings"), manager, SLOT(showDialog())); menu.addSeparator(); QList entries = p_QupZilla->weView()->webPage()->adBlockedEntries(); - if (entries.isEmpty()) + if (entries.isEmpty()) { menu.addAction(tr("No content blocked"))->setEnabled(false); + } else { menu.addAction(tr("Blocked URL (AdBlock Rule) - click to edit rule"))->setEnabled(false); - foreach (WebPage::AdBlockedEntry entry, entries) { + foreach(WebPage::AdBlockedEntry entry, entries) { QString address = entry.url.toString().right(55); menu.addAction(tr("%1 with (%2)").arg(address, entry.rule), manager, SLOT(showRule()))->setData(entry.rule); } @@ -61,10 +62,12 @@ void AdBlockIcon::learnAboutRules() void AdBlockIcon::setEnabled(bool enabled) { - if (enabled) + if (enabled) { setPixmap(QPixmap(":icons/other/adblock.png")); - else + } + else { setPixmap(QPixmap(":icons/other/adblock-disabled.png")); + } } AdBlockIcon::~AdBlockIcon() diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 5200774a9..b231316da 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -60,21 +60,24 @@ AdBlockManager::AdBlockManager(QObject* parent) , m_adBlockDialog(0) , m_adBlockNetwork(0) , m_adBlockPage(0) + , m_subscription(0) { } AdBlockManager* AdBlockManager::instance() { - if (!s_adBlockManager) + if (!s_adBlockManager) { s_adBlockManager = new AdBlockManager(mApp->networkManager()); + } return s_adBlockManager; } void AdBlockManager::setEnabled(bool enabled) { - if (isEnabled() == enabled) + if (isEnabled() == enabled) { return; + } m_enabled = enabled; emit rulesChanged(); mApp->sendMessages(MainApplication::SetAdBlockIconEnabled, enabled); @@ -82,25 +85,28 @@ void AdBlockManager::setEnabled(bool enabled) AdBlockNetwork* AdBlockManager::network() { - if (!m_adBlockNetwork) + if (!m_adBlockNetwork) { m_adBlockNetwork = new AdBlockNetwork(this); + } return m_adBlockNetwork; } AdBlockPage* AdBlockManager::page() { - if (!m_adBlockPage) + if (!m_adBlockPage) { m_adBlockPage = new AdBlockPage(this); + } return m_adBlockPage; } void AdBlockManager::load() { - if (m_loaded) + if (m_loaded) { return; + } m_loaded = true; - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("AdBlock"); m_enabled = settings.value("enabled", m_enabled).toBool(); settings.endGroup(); @@ -112,11 +118,12 @@ void AdBlockManager::load() void AdBlockManager::save() { - if (!m_loaded) + if (!m_loaded) { return; + } m_subscription->saveRules(); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup(QLatin1String("AdBlock")); settings.setValue(QLatin1String("enabled"), m_enabled); settings.endGroup(); @@ -124,8 +131,9 @@ void AdBlockManager::save() AdBlockDialog* AdBlockManager::showDialog() { - if (!m_adBlockDialog) + if (!m_adBlockDialog) { m_adBlockDialog = new AdBlockDialog(mApp->getWindow()); + } m_adBlockDialog->show(); return m_adBlockDialog; diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index a05b4231d..5b51a97a6 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -64,7 +64,7 @@ signals: void rulesChanged(); public: - AdBlockManager(QObject *parent = 0); + AdBlockManager(QObject* parent = 0); ~AdBlockManager(); void load(); @@ -73,8 +73,8 @@ public: bool isEnabled() { if (!m_loaded) load(); return m_enabled; } AdBlockSubscription* subscription() { return m_subscription; } - AdBlockNetwork *network(); - AdBlockPage *page(); + AdBlockNetwork* network(); + AdBlockPage* page(); public slots: void setEnabled(bool enabled); diff --git a/src/adblock/adblocknetwork.cpp b/src/adblock/adblocknetwork.cpp index ac6ee3648..3a53a4769 100644 --- a/src/adblock/adblocknetwork.cpp +++ b/src/adblock/adblocknetwork.cpp @@ -50,7 +50,7 @@ #include "mainapplication.h" #include "webpage.h" -AdBlockNetwork::AdBlockNetwork(QObject *parent) +AdBlockNetwork::AdBlockNetwork(QObject* parent) : QObject(parent) { } @@ -58,31 +58,36 @@ AdBlockNetwork::AdBlockNetwork(QObject *parent) QNetworkReply* AdBlockNetwork::block(const QNetworkRequest &request) { QUrl url = request.url(); - if (url.scheme() == "data") + if (url.scheme() == "data") { return 0; + } AdBlockManager* manager = AdBlockManager::instance(); - if (!manager->isEnabled()) + if (!manager->isEnabled()) { return 0; + } QString urlString = url.toEncoded(); const AdBlockRule* blockedRule = 0; AdBlockSubscription* subscription = manager->subscription(); - if (subscription->allow(urlString)) + if (subscription->allow(urlString)) { return 0; + } - if (const AdBlockRule* rule = subscription->block(urlString)) + if (const AdBlockRule* rule = subscription->block(urlString)) { blockedRule = rule; + } if (blockedRule) { - QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); - WebPage* webPage = (WebPage*)(v.value()); - if (webPage) - webPage->addAdBlockRule(blockedRule->filter(), request.url()); + QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); + WebPage* webPage = (WebPage*)(v.value()); + if (webPage) { + webPage->addAdBlockRule(blockedRule->filter(), request.url()); + } - AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this); - return reply; + AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this); + return reply; } return 0; } diff --git a/src/adblock/adblocknetwork.h b/src/adblock/adblocknetwork.h index fed8fad8c..ac3a9e71b 100644 --- a/src/adblock/adblocknetwork.h +++ b/src/adblock/adblocknetwork.h @@ -55,8 +55,8 @@ class AdBlockNetwork : public QObject Q_OBJECT public: - AdBlockNetwork(QObject *parent = 0); - QNetworkReply *block(const QNetworkRequest &request); + AdBlockNetwork(QObject* parent = 0); + QNetworkReply* block(const QNetworkRequest &request); }; #endif // ADBLOCKNETWORK_H diff --git a/src/adblock/adblockpage.cpp b/src/adblock/adblockpage.cpp index 8b20ceb5a..34501123d 100644 --- a/src/adblock/adblockpage.cpp +++ b/src/adblock/adblockpage.cpp @@ -42,20 +42,22 @@ // #define ADBLOCKPAGE_DEBUG -AdBlockPage::AdBlockPage(QObject *parent) +AdBlockPage::AdBlockPage(QObject* parent) : QObject(parent) { } -void AdBlockPage::checkRule(const AdBlockRule *rule, QWebPage *page, const QString &host) +void AdBlockPage::checkRule(const AdBlockRule* rule, QWebPage* page, const QString &host) { - if (!rule->isEnabled()) + if (!rule->isEnabled()) { return; + } QString filter = rule->filter(); int offset = filter.indexOf(QLatin1String("##")); - if (offset == -1) + if (offset == -1) { return; + } QString selectorQuery; if (offset > 0) { @@ -64,33 +66,38 @@ void AdBlockPage::checkRule(const AdBlockRule *rule, QWebPage *page, const QStri QStringList domains = domainRules.split(QLatin1Char(',')); bool match = false; - foreach (const QString &domain, domains) { + foreach(const QString & domain, domains) { bool reverse = (domain[0] == QLatin1Char('~')); if (reverse) { QString xdomain = domain.mid(1); - if (host.endsWith(xdomain)) + if (host.endsWith(xdomain)) { return; + } match = true; } - if (host.endsWith(domain)) + if (host.endsWith(domain)) { match = true; + } } - if (!match) + if (!match) { return; + } } - if (offset == 0) + if (offset == 0) { selectorQuery = filter.mid(2); + } Q_UNUSED(page); #if QT_VERSION >= 0x040600 QWebElement document = page->mainFrame()->documentElement(); QWebElementCollection elements = document.findAll(selectorQuery); #if defined(ADBLOCKPAGE_DEBUG) - if (elements.count() != 0) + if (elements.count() != 0) { qDebug() << "AdBlockPage::" << __FUNCTION__ << "blocking" << elements.count() << "items" << selectorQuery << elements.count() << "rule:" << rule->filter(); + } #endif - foreach (QWebElement element, elements) { + foreach(QWebElement element, elements) { element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); element.removeFromDocument(); } @@ -98,21 +105,23 @@ void AdBlockPage::checkRule(const AdBlockRule *rule, QWebPage *page, const QStri #endif } -void AdBlockPage::applyRulesToPage(QWebPage *page) +void AdBlockPage::applyRulesToPage(QWebPage* page) { - if (!page || !page->mainFrame()) + if (!page || !page->mainFrame()) { return; - AdBlockManager *manager = AdBlockManager::instance(); - if (!manager->isEnabled()) + } + AdBlockManager* manager = AdBlockManager::instance(); + if (!manager->isEnabled()) { return; + } #if QT_VERSION >= 0x040600 QString host = page->mainFrame()->url().host(); AdBlockSubscription* subscription = manager->subscription(); QList rules = subscription->pageRules(); - foreach (const AdBlockRule *rule, rules) { - checkRule(rule, page, host); - } + foreach(const AdBlockRule * rule, rules) { + checkRule(rule, page, host); + } #endif } diff --git a/src/adblock/adblockpage.h b/src/adblock/adblockpage.h index a1f3b0d21..a2f9cc115 100644 --- a/src/adblock/adblockpage.h +++ b/src/adblock/adblockpage.h @@ -38,12 +38,12 @@ class AdBlockPage : public QObject Q_OBJECT public: - AdBlockPage(QObject *parent = 0); + AdBlockPage(QObject* parent = 0); - void applyRulesToPage(QWebPage *page); + void applyRulesToPage(QWebPage* page); private: - void checkRule(const AdBlockRule *rule, QWebPage *page, const QString &host); + void checkRule(const AdBlockRule* rule, QWebPage* page, const QString &host); }; #endif // ADBLOCKPAGE_H diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp index d36480dac..50ae19e21 100644 --- a/src/adblock/adblockrule.cpp +++ b/src/adblock/adblockrule.cpp @@ -74,11 +74,13 @@ void AdBlockRule::setFilter(const QString &filter) bool regExpRule = false; if (filter.startsWith(QLatin1String("!")) - || filter.trimmed().isEmpty()) + || filter.trimmed().isEmpty()) { m_enabled = false; + } - if (filter.contains(QLatin1String("##"))) + if (filter.contains(QLatin1String("##"))) { m_cssRule = true; + } QString parsedLine = filter; if (parsedLine.startsWith(QLatin1String("@@"))) { @@ -125,24 +127,27 @@ bool AdBlockRule::networkMatch(const QString &encodedUrl) const bool matched = m_regExp.indexIn(encodedUrl) != -1; if (matched - && !m_options.isEmpty()) { + && !m_options.isEmpty()) { // we only support domain right now if (m_options.count() == 1) { - foreach (const QString &option, m_options) { + foreach(const QString & option, m_options) { if (option.startsWith("domain=")) { QUrl url = QUrl::fromEncoded(encodedUrl.toUtf8()); QString host = url.host(); QStringList domainOptions = option.mid(7).split('|'); - foreach (QString domainOption, domainOptions) { + foreach(QString domainOption, domainOptions) { bool negate = domainOption.at(0) == '~'; - if (negate) + if (negate) { domainOption = domainOption.mid(1); + } bool hostMatched = domainOption == host; - if (hostMatched && !negate) + if (hostMatched && !negate) { return true; - if (!hostMatched && negate) + } + if (!hostMatched && negate) { return true; + } } } } @@ -180,7 +185,8 @@ void AdBlockRule::setEnabled(bool enabled) m_enabled = enabled; if (!enabled) { m_filter = QLatin1String("!") + m_filter; - } else { + } + else { m_filter = m_filter.mid(1); } } @@ -190,21 +196,22 @@ QString AdBlockRule::regExpPattern() const return m_regExp.pattern(); } -static QString convertPatternToRegExp(const QString &wildcardPattern) { +static QString convertPatternToRegExp(const QString &wildcardPattern) +{ QString pattern = wildcardPattern; return pattern.replace(QRegExp(QLatin1String("\\*+")), QLatin1String("*")) // remove multiple wildcards - .replace(QRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder - .replace(QRegExp(QLatin1String("^(\\*)")), QLatin1String("")) // remove leading wildcards - .replace(QRegExp(QLatin1String("(\\*)$")), QLatin1String("")) - .replace(QRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols - .replace(QRegExp(QLatin1String("^\\\\\\|\\\\\\|")), - QLatin1String("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")) // process extended anchor at expression start - .replace(QRegExp(QLatin1String("\\\\\\^")), - QLatin1String("(?:[^\\w\\d\\-.%]|$)")) // process separator placeholders - .replace(QRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start - .replace(QRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end - .replace(QRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")) // replace wildcards by .* - ; + .replace(QRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder + .replace(QRegExp(QLatin1String("^(\\*)")), QLatin1String("")) // remove leading wildcards + .replace(QRegExp(QLatin1String("(\\*)$")), QLatin1String("")) + .replace(QRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols + .replace(QRegExp(QLatin1String("^\\\\\\|\\\\\\|")), + QLatin1String("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")) // process extended anchor at expression start + .replace(QRegExp(QLatin1String("\\\\\\^")), + QLatin1String("(?:[^\\w\\d\\-.%]|$)")) // process separator placeholders + .replace(QRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start + .replace(QRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end + .replace(QRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")) // replace wildcards by .* + ; } void AdBlockRule::setPattern(const QString &pattern, bool isRegExp) diff --git a/src/adblock/adblocksubscription.cpp b/src/adblock/adblocksubscription.cpp index 4271d4f85..85afffa40 100644 --- a/src/adblock/adblocksubscription.cpp +++ b/src/adblock/adblocksubscription.cpp @@ -56,20 +56,22 @@ AdBlockSubscription::AdBlockSubscription(QObject* parent) void AdBlockSubscription::loadRules() { - QString fileName = mApp->getActiveProfilPath()+"adblocklist.txt"; + QString fileName = mApp->getActiveProfilPath() + "adblocklist.txt"; QFile file(fileName); if (file.exists()) { if (!file.open(QFile::ReadOnly)) { qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for reading" << fileName; - } else { + } + else { QTextStream textStream(&file); QString header = textStream.readLine(1024); if (!header.startsWith("[Adblock")) { qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "adblock file does not start with [Adblock" << fileName << "Header:" << header; file.close(); file.remove(); - } else { + } + else { m_rules.clear(); while (!textStream.atEnd()) { QString line = textStream.readLine(); @@ -84,8 +86,9 @@ void AdBlockSubscription::loadRules() void AdBlockSubscription::updateNow() { - if (m_downloading) + if (m_downloading) { return; + } QNetworkRequest request(QUrl("https://easylist-downloads.adblockplus.org/easylist.txt")); QNetworkReply* reply = mApp->networkManager()->get(request); @@ -96,18 +99,21 @@ void AdBlockSubscription::updateNow() void AdBlockSubscription::rulesDownloaded() { QNetworkReply* reply = qobject_cast(sender()); - if (!reply) + if (!reply) { return; + } QByteArray response = reply->readAll(); reply->close(); reply->deleteLater(); - if (reply->error() != QNetworkReply::NoError) + if (reply->error() != QNetworkReply::NoError) { return; + } - if (response.isEmpty()) + if (response.isEmpty()) { return; + } QString fileName = mApp->getActiveProfilPath() + "adblocklist.txt"; QFile file(fileName); @@ -119,15 +125,16 @@ void AdBlockSubscription::rulesDownloaded() response = response.left(response.indexOf("!-----------------General element hiding rules-----------------!")); bool customRules = false; - foreach (const AdBlockRule rule, allRules()) { + foreach(const AdBlockRule & rule, allRules()) { if (rule.filter().contains("*******- user custom filters")) { customRules = true; response.append("! *******- user custom filters -*************\n"); continue; } - if (!customRules) + if (!customRules) { continue; - response.append(rule.filter()+"\n"); + } + response.append(rule.filter() + "\n"); } file.write(response); @@ -139,7 +146,7 @@ void AdBlockSubscription::rulesDownloaded() void AdBlockSubscription::saveRules() { - QString fileName = mApp->getActiveProfilPath()+"adblocklist.txt"; + QString fileName = mApp->getActiveProfilPath() + "adblocklist.txt"; QFile file(fileName); if (!file.open(QFile::ReadWrite | QIODevice::Truncate)) { @@ -149,24 +156,26 @@ void AdBlockSubscription::saveRules() QTextStream textStream(&file); textStream << "[Adblock Plus 1.1.1]" << endl; - foreach (const AdBlockRule &rule, m_rules) - textStream << rule.filter() << endl; + foreach(const AdBlockRule & rule, m_rules) + textStream << rule.filter() << endl; } const AdBlockRule* AdBlockSubscription::allow(const QString &urlString) const { - foreach (const AdBlockRule* rule, m_networkExceptionRules) { - if (rule->networkMatch(urlString)) + foreach(const AdBlockRule * rule, m_networkExceptionRules) { + if (rule->networkMatch(urlString)) { return rule; + } } return 0; } const AdBlockRule* AdBlockSubscription::block(const QString &urlString) const { - foreach (const AdBlockRule* rule, m_networkBlockRules) { - if (rule->networkMatch(urlString)) + foreach(const AdBlockRule * rule, m_networkBlockRules) { + if (rule->networkMatch(urlString)) { return rule; + } } return 0; } @@ -186,8 +195,9 @@ int AdBlockSubscription::addRule(const AdBlockRule &rule) void AdBlockSubscription::removeRule(int offset) { - if (offset < 0 || offset >= m_rules.count()) + if (offset < 0 || offset >= m_rules.count()) { return; + } m_rules.removeAt(offset); populateCache(); emit rulesChanged(); @@ -195,8 +205,9 @@ void AdBlockSubscription::removeRule(int offset) void AdBlockSubscription::replaceRule(const AdBlockRule &rule, int offset) { - if (offset < 0 || offset >= m_rules.count()) + if (offset < 0 || offset >= m_rules.count()) { return; + } m_rules[offset] = rule; populateCache(); emit rulesChanged(); @@ -210,8 +221,9 @@ void AdBlockSubscription::populateCache() for (int i = 0; i < m_rules.count(); ++i) { const AdBlockRule* rule = &m_rules.at(i); - if (!rule->isEnabled()) + if (!rule->isEnabled()) { continue; + } if (rule->isCSSRule()) { m_pageRules.append(rule); @@ -220,7 +232,8 @@ void AdBlockSubscription::populateCache() if (rule->isException()) { m_networkExceptionRules.append(rule); - } else { + } + else { m_networkBlockRules.append(rule); } } diff --git a/src/adblock/adblocksubscription.h b/src/adblock/adblocksubscription.h index 9c532438d..c53934852 100644 --- a/src/adblock/adblocksubscription.h +++ b/src/adblock/adblocksubscription.h @@ -67,7 +67,7 @@ signals: void rulesChanged(); public: - AdBlockSubscription(QObject *parent = 0); + AdBlockSubscription(QObject* parent = 0); QString title() const { return m_title; } void setTitle(const QString &title) { m_title = title; } diff --git a/src/app/autosaver.cpp b/src/app/autosaver.cpp index 2ea1e1165..d5bb440ea 100644 --- a/src/app/autosaver.cpp +++ b/src/app/autosaver.cpp @@ -19,15 +19,17 @@ #include "mainapplication.h" AutoSaver::AutoSaver(QObject* parent) : - QObject(parent) + QObject(parent) { - m_timer.start(1000*5, this); + m_timer.start(1000 * 5, this); } void AutoSaver::timerEvent(QTimerEvent* event) { - if (event->timerId() == m_timer.timerId() && mApp->isStateChanged()) + if (event->timerId() == m_timer.timerId() && mApp->isStateChanged()) { emit saveApp(); - else + } + else { QObject::timerEvent(event); + } } diff --git a/src/app/commandlineoptions.cpp b/src/app/commandlineoptions.cpp index 595025eb8..81c383c9a 100644 --- a/src/app/commandlineoptions.cpp +++ b/src/app/commandlineoptions.cpp @@ -18,10 +18,10 @@ #include "commandlineoptions.h" #include "qupzilla.h" -CommandLineOptions::CommandLineOptions(int &argc, char **argv) : - QObject(0) - ,m_argc(argc) - ,m_argv(argv) +CommandLineOptions::CommandLineOptions(int &argc, char** argv) : + QObject(0) + , m_argc(argc) + , m_argv(argv) { parseActions(); } @@ -133,7 +133,7 @@ void CommandLineOptions::parseActions() } } - QString url(m_argv[m_argc-1]); + QString url(m_argv[m_argc - 1]); if (m_argc > 1 && !url.isEmpty() && !url.startsWith("-")) { found = true; cout << "starting with url " << url.toAscii().data() << endl; diff --git a/src/app/commandlineoptions.h b/src/app/commandlineoptions.h index c57b06ba0..9655de937 100644 --- a/src/app/commandlineoptions.h +++ b/src/app/commandlineoptions.h @@ -33,7 +33,7 @@ public: QString text; }; - explicit CommandLineOptions(int &argc, char **argv); + explicit CommandLineOptions(int &argc, char** argv); QList getActions() { return m_actions; } private: @@ -41,7 +41,7 @@ private: void parseActions(); int m_argc; - char **m_argv; + char** m_argv; QList m_actions; }; diff --git a/src/app/mainapplication.cpp b/src/app/mainapplication.cpp index d5423730b..7bc3c5f45 100644 --- a/src/app/mainapplication.cpp +++ b/src/app/mainapplication.cpp @@ -42,7 +42,7 @@ #include "searchenginesmanager.h" #include "operaimporter.h" -MainApplication::MainApplication(const QList &cmdActions, int &argc, char **argv) +MainApplication::MainApplication(const QList &cmdActions, int &argc, char** argv) : QtSingleApplication("QupZillaWebBrowser", argc, argv) , m_cookiemanager(0) , m_browsingLibrary(0) @@ -83,7 +83,7 @@ MainApplication::MainApplication(const QList &cm QString startProfile; if (argc > 1) { - foreach (CommandLineOptions::ActionPair pair, cmdActions) { + foreach(CommandLineOptions::ActionPair pair, cmdActions) { switch (pair.action) { case CommandLineOptions::StartWithoutAddons: noAddons = true; @@ -124,28 +124,33 @@ MainApplication::MainApplication(const QList &cm setOrganizationDomain("qupzilla"); QString homePath = QDir::homePath(); - homePath+="/.qupzilla/"; + homePath += "/.qupzilla/"; checkSettingsDir(); QSettings::setDefaultFormat(QSettings::IniFormat); if (startProfile.isEmpty()) { - QSettings settings(homePath+"profiles/profiles.ini", QSettings::IniFormat); - if (settings.value("Profiles/startProfile","default").toString().contains("/")) - m_activeProfil=homePath+"profiles/default/"; - else - m_activeProfil=homePath+"profiles/"+settings.value("Profiles/startProfile","default").toString()+"/"; - } else - m_activeProfil = homePath+"profiles/"+startProfile+"/"; + QSettings settings(homePath + "profiles/profiles.ini", QSettings::IniFormat); + if (settings.value("Profiles/startProfile", "default").toString().contains("/")) { + m_activeProfil = homePath + "profiles/default/"; + } + else { + m_activeProfil = homePath + "profiles/" + settings.value("Profiles/startProfile", "default").toString() + "/"; + } + } + else { + m_activeProfil = homePath + "profiles/" + startProfile + "/"; + } ProfileUpdater u(m_activeProfil, DATADIR); u.checkProfile(); connectDatabase(); - QSettings settings2(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings2(m_activeProfil + "settings.ini", QSettings::IniFormat); settings2.beginGroup("SessionRestore"); - if (settings2.value("isRunning",false).toBool() ) + if (settings2.value("isRunning", false).toBool()) { settings2.setValue("isCrashed", true); + } settings2.setValue("isRunning", true); settings2.endGroup(); @@ -156,14 +161,15 @@ MainApplication::MainApplication(const QList &cm QupZilla* qupzilla = new QupZilla(QupZilla::FirstAppWindow, startUrl); m_mainWindows.append(qupzilla); - connect(qupzilla, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool))); + connect(qupzilla, SIGNAL(message(MainApplication::MessageType, bool)), this, SLOT(sendMessages(MainApplication::MessageType, bool))); qupzilla->show(); AutoSaver* saver = new AutoSaver(); connect(saver, SIGNAL(saveApp()), this, SLOT(saveStateSlot())); - if (settings2.value("Web-Browser-Settings/CheckUpdates", true).toBool()) + if (settings2.value("Web-Browser-Settings/CheckUpdates", true).toBool()) { m_updater = new Updater(qupzilla); + } if (noAddons) { settings2.setValue("Plugin-Settings/AllowedPlugins", QStringList()); @@ -175,12 +181,12 @@ MainApplication::MainApplication(const QList &cm loadSettings(); QTimer::singleShot(2000, this, SLOT(restoreCursor())); - QTimer::singleShot(10*1000, this, SLOT(setupJumpList())); + QTimer::singleShot(10 * 1000, this, SLOT(setupJumpList())); } void MainApplication::loadSettings() { - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("Themes"); QString activeTheme = settings.value("activeTheme", #ifdef Q_WS_X11 @@ -188,7 +194,7 @@ void MainApplication::loadSettings() #else "windows" #endif - ).toString(); + ).toString(); settings.endGroup(); m_activeThemePath = THEMESDIR + activeTheme + "/"; QFile cssFile(m_activeThemePath + "main.css"); @@ -220,18 +226,18 @@ void MainApplication::loadSettings() webSettings(); //Web browsing settings settings.beginGroup("Web-Browser-Settings"); - bool allowFlash = settings.value("allowFlash",true).toBool(); - bool allowJavaScript = settings.value("allowJavaScript",true).toBool(); - bool allowJavaScriptOpenWindow = settings.value("allowJavaScriptOpenWindow",false).toBool(); - bool allowJava = settings.value("allowJava",true).toBool(); - bool allowPersistentStorage = settings.value("allowPersistentStorage",true).toBool(); - bool allowImages = settings.value("autoLoadImages",true).toBool(); + bool allowFlash = settings.value("allowFlash", true).toBool(); + bool allowJavaScript = settings.value("allowJavaScript", true).toBool(); + bool allowJavaScriptOpenWindow = settings.value("allowJavaScriptOpenWindow", false).toBool(); + bool allowJava = settings.value("allowJava", true).toBool(); + bool allowPersistentStorage = settings.value("allowPersistentStorage", true).toBool(); + bool allowImages = settings.value("autoLoadImages", true).toBool(); bool dnsPrefetch = settings.value("DNS-Prefetch", false).toBool(); bool jsClipboard = settings.value("JavaScriptCanAccessClipboard", true).toBool(); bool linkInFocuschain = settings.value("IncludeLinkInFocusChain", false).toBool(); bool zoomTextOnly = settings.value("zoomTextOnly", false).toBool(); bool printElBg = settings.value("PrintElementBackground", true).toBool(); - int maxCachedPages = settings.value("maximumCachedPages",3).toInt(); + int maxCachedPages = settings.value("maximumCachedPages", 3).toInt(); int scrollingLines = settings.value("wheelScrollLines", wheelScrollLines()).toInt(); QUrl userStyleSheet = settings.value("userStyleSheet", QUrl()).toUrl(); m_defaultZoom = settings.value("DefaultZoom", 100).toInt(); @@ -264,25 +270,28 @@ void MainApplication::loadSettings() m_websettings->setFontFamily(QWebSettings::FixedFont, settings.value("FixedFont", m_websettings->fontFamily(QWebSettings::FixedFont)).toString()); m_websettings->setFontFamily(QWebSettings::SansSerifFont, settings.value("SansSerifFont", m_websettings->fontFamily(QWebSettings::SansSerifFont)).toString()); m_websettings->setFontFamily(QWebSettings::SerifFont, settings.value("SerifFont", m_websettings->fontFamily(QWebSettings::SerifFont)).toString()); - m_websettings->setFontSize(QWebSettings::DefaultFontSize, settings.value("DefaultFontSize", m_websettings->fontSize(QWebSettings::DefaultFontSize)).toInt() ); - m_websettings->setFontSize(QWebSettings::DefaultFixedFontSize, settings.value("FixedFontSize", m_websettings->fontSize(QWebSettings::DefaultFixedFontSize)).toInt() ); + m_websettings->setFontSize(QWebSettings::DefaultFontSize, settings.value("DefaultFontSize", m_websettings->fontSize(QWebSettings::DefaultFontSize)).toInt()); + m_websettings->setFontSize(QWebSettings::DefaultFixedFontSize, settings.value("FixedFontSize", m_websettings->fontSize(QWebSettings::DefaultFixedFontSize)).toInt()); m_websettings->setUserStyleSheetUrl(userStyleSheet); m_websettings->setDefaultTextEncoding("System"); - m_websettings->setWebGraphic(QWebSettings::DefaultFrameIconGraphic, IconProvider::fromTheme("text-plain").pixmap(16,16)); + m_websettings->setWebGraphic(QWebSettings::DefaultFrameIconGraphic, IconProvider::fromTheme("text-plain").pixmap(16, 16)); - if (allowPersistentStorage) m_websettings->enablePersistentStorage(m_activeProfil); + if (allowPersistentStorage) { + m_websettings->enablePersistentStorage(m_activeProfil); + } m_websettings->setMaximumPagesInCache(maxCachedPages); setWheelScrollLines(scrollingLines); - if (m_downloadManager) + if (m_downloadManager) { m_downloadManager->loadSettings(); + } } void MainApplication::restoreCursor() { - QApplication::restoreOverrideCursor(); + QApplication::restoreOverrideCursor(); } void MainApplication::setupJumpList() @@ -292,9 +301,10 @@ void MainApplication::setupJumpList() QupZilla* MainApplication::getWindow() { - for(int i=0; ishow(); + } } QupZilla* actWin = getWindow(); @@ -348,29 +362,33 @@ void MainApplication::receiveAppMessage(QString message) void MainApplication::addNewTab(const QUrl &url) { - if (!getWindow()) + if (!getWindow()) { return; + } getWindow()->tabWidget()->addView(url); } void MainApplication::makeNewWindow(bool tryRestore, const QUrl &startUrl) { QupZilla::StartBehaviour behaviour; - if (tryRestore) + if (tryRestore) { behaviour = QupZilla::OtherRestoredWindow; - else + } + else { behaviour = QupZilla::NewWindow; + } QupZilla* newWindow = new QupZilla(behaviour, startUrl); - connect(newWindow, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool))); + connect(newWindow, SIGNAL(message(MainApplication::MessageType, bool)), this, SLOT(sendMessages(MainApplication::MessageType, bool))); m_mainWindows.append(newWindow); newWindow->show(); } void MainApplication::connectDatabase() { - if (m_databaseConnected) + if (m_databaseConnected) { return; + } QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(m_activeProfil + "browsedata.db"); @@ -379,8 +397,9 @@ void MainApplication::connectDatabase() db.setDatabaseName(m_activeProfil + "browsedata.db"); qWarning("Cannot find SQLite database file! Copying and using the defaults!"); } - if (!db.open()) + if (!db.open()) { qWarning("Cannot open SQLite database! Continuing without database...."); + } m_databaseConnected = true; } @@ -388,20 +407,22 @@ void MainApplication::connectDatabase() void MainApplication::translateApp() { QLocale locale; - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("Language"); - QString file = settings.value("language",locale.name()+".qm").toString(); + QString file = settings.value("language", locale.name() + ".qm").toString(); QString shortLoc = file.left(2); - if (file == "" || !QFile::exists(TRANSLATIONSDIR + file) ) + if (file == "" || !QFile::exists(TRANSLATIONSDIR + file)) { return; + } QTranslator* app = new QTranslator(); - app->load(DATADIR+"locale/"+file); + app->load(DATADIR + "locale/" + file); QTranslator* sys = new QTranslator(); - if (QFile::exists(TRANSLATIONSDIR + "qt_" + shortLoc + ".qm")) + if (QFile::exists(TRANSLATIONSDIR + "qt_" + shortLoc + ".qm")) { sys->load(TRANSLATIONSDIR + "qt_" + shortLoc + ".qm"); + } m_activeLanguage = file; @@ -416,22 +437,25 @@ void MainApplication::quitApplication() return; } m_isClosing = true; - if (m_mainWindows.count() > 0) + if (m_mainWindows.count() > 0) { saveStateSlot(); + } - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("SessionRestore"); - settings.setValue("isRunning",false); + settings.setValue("isRunning", false); settings.setValue("isCrashed", false); settings.endGroup(); bool deleteCookies = settings.value("Web-Browser-Settings/deleteCookiesOnClose", false).toBool(); bool deleteHistory = settings.value("Web-Browser-Settings/deleteHistoryOnClose", false).toBool(); - if (deleteCookies) - QFile::remove(m_activeProfil+"cookies.dat"); - if (deleteHistory) + if (deleteCookies) { + QFile::remove(m_activeProfil + "cookies.dat"); + } + if (deleteHistory) { m_historymodel->clearHistory(); + } m_searchEnginesManager->saveSettings(); cookieJar()->saveCookies(); @@ -447,43 +471,49 @@ void MainApplication::quitApplication() BrowsingLibrary* MainApplication::browsingLibrary() { - if (!m_browsingLibrary) + if (!m_browsingLibrary) { m_browsingLibrary = new BrowsingLibrary(getWindow()); + } return m_browsingLibrary; } PluginProxy* MainApplication::plugins() { - if (!m_plugins) + if (!m_plugins) { m_plugins = new PluginProxy(); + } return m_plugins; } CookieManager* MainApplication::cookieManager() { - if (!m_cookiemanager) + if (!m_cookiemanager) { m_cookiemanager = new CookieManager(); + } return m_cookiemanager; } HistoryModel* MainApplication::history() { - if (!m_historymodel) + if (!m_historymodel) { m_historymodel = new HistoryModel(getWindow()); + } return m_historymodel; } QWebSettings* MainApplication::webSettings() { - if (!m_websettings) + if (!m_websettings) { m_websettings = QWebSettings::globalSettings(); + } return m_websettings; } NetworkManager* MainApplication::networkManager() { - if (!m_networkmanager) + if (!m_networkmanager) { m_networkmanager = new NetworkManager(getWindow()); + } return m_networkmanager; } @@ -498,50 +528,57 @@ CookieJar* MainApplication::cookieJar() RSSManager* MainApplication::rssManager() { - if (!m_rssmanager) + if (!m_rssmanager) { m_rssmanager = new RSSManager(getWindow()); + } return m_rssmanager; } BookmarksModel* MainApplication::bookmarksModel() { - if (!m_bookmarksModel) + if (!m_bookmarksModel) { m_bookmarksModel = new BookmarksModel(this); + } return m_bookmarksModel; } DownloadManager* MainApplication::downManager() { - if (!m_downloadManager) + if (!m_downloadManager) { m_downloadManager = new DownloadManager(); + } return m_downloadManager; } AutoFillModel* MainApplication::autoFill() { - if (!m_autofill) + if (!m_autofill) { m_autofill = new AutoFillModel(getWindow()); + } return m_autofill; } SearchEnginesManager* MainApplication::searchEnginesManager() { - if (!m_searchEnginesManager) + if (!m_searchEnginesManager) { m_searchEnginesManager = new SearchEnginesManager(); + } return m_searchEnginesManager; } DesktopNotificationsFactory* MainApplication::desktopNotifications() { - if (!m_desktopNotifications) + if (!m_desktopNotifications) { m_desktopNotifications = new DesktopNotificationsFactory(this); + } return m_desktopNotifications; } void MainApplication::aboutToCloseWindow(QupZilla* window) { - if (!window) + if (!window) { return; + } m_mainWindows.removeOne(window); } @@ -551,14 +588,15 @@ static const int sessionVersion = 0x0002; bool MainApplication::saveStateSlot() { - if (m_websettings->testAttribute(QWebSettings::PrivateBrowsingEnabled) || m_isRestoring) + if (m_websettings->testAttribute(QWebSettings::PrivateBrowsingEnabled) || m_isRestoring) { return false; + } - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("SessionRestore"); - settings.setValue("restoreSession",false); + settings.setValue("restoreSession", false); - QFile file(m_activeProfil+"session.dat"); + QFile file(m_activeProfil + "session.dat"); file.open(QIODevice::WriteOnly); QDataStream stream(&file); @@ -566,19 +604,22 @@ bool MainApplication::saveStateSlot() stream << m_mainWindows.count(); for (int i = 0; i < m_mainWindows.count(); i++) { stream << m_mainWindows.at(i)->tabWidget()->saveState(); - if (m_mainWindows.at(i)->isFullScreen()) + if (m_mainWindows.at(i)->isFullScreen()) { stream << QByteArray(); - else + } + else { stream << m_mainWindows.at(i)->saveState(); + } } file.close(); - settings.setValue("restoreSession",true); + settings.setValue("restoreSession", true); settings.endGroup(); QupZilla* qupzilla_ = getWindow(); - if (qupzilla_) + if (qupzilla_) { qupzilla_->tabWidget()->savePinnedTabs(); + } return true; } @@ -586,29 +627,29 @@ bool MainApplication::saveStateSlot() bool MainApplication::restoreStateSlot(QupZilla* window) { m_isRestoring = true; - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); int afterStart = settings.value("Web-URL-Settings/afterLaunch", 1).toInt(); settings.beginGroup("SessionRestore"); - if (!settings.value("restoreSession",false).toBool()) { + if (!settings.value("restoreSession", false).toBool()) { m_isRestoring = false; return false; } - if (settings.value("isCrashed",false).toBool() && afterStart != 2) { + if (settings.value("isCrashed", false).toBool() && afterStart != 2) { QMessageBox::StandardButton button = QMessageBox::warning(window, tr("Last session crashed"), - tr("QupZilla crashed :-(
Oops, last session of QupZilla ends with its crash. We are very sorry. Would you try to restore saved state?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + tr("QupZilla crashed :-(
Oops, last session of QupZilla ends with its crash. We are very sorry. Would you try to restore saved state?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (button != QMessageBox::Yes) { m_isRestoring = false; return false; } } - if (!QFile::exists(m_activeProfil+"session.dat")) { + if (!QFile::exists(m_activeProfil + "session.dat")) { m_isRestoring = false; return false; } - settings.setValue("isCrashed",false); - QFile file(m_activeProfil+"session.dat"); + settings.setValue("isCrashed", false); + QFile file(m_activeProfil + "session.dat"); file.open(QIODevice::ReadOnly); QDataStream stream(&file); @@ -636,7 +677,7 @@ bool MainApplication::restoreStateSlot(QupZilla* window) QupZilla* window = new QupZilla(QupZilla::OtherRestoredWindow); m_mainWindows.append(window); - connect(window, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(sendMessages(MainApplication::MessageType,bool))); + connect(window, SIGNAL(message(MainApplication::MessageType, bool)), this, SLOT(sendMessages(MainApplication::MessageType, bool))); QEventLoop eLoop; connect(window, SIGNAL(startingCompleted()), &eLoop, SLOT(quit())); eLoop.exec(); @@ -668,8 +709,9 @@ bool MainApplication::checkSettingsDir() */ QString homePath = QDir::homePath() + "/.qupzilla/"; - if (QDir(homePath).exists() && QFile(homePath + "profiles/profiles.ini").exists()) - return true; + if (QDir(homePath).exists() && QFile(homePath + "profiles/profiles.ini").exists()) { + return true; + } std::cout << "Creating new profile directory" << std::endl; diff --git a/src/app/mainapplication.h b/src/app/mainapplication.h index 4fac2b981..d10b60b37 100644 --- a/src/app/mainapplication.h +++ b/src/app/mainapplication.h @@ -56,15 +56,15 @@ public: QString PLUGINSDIR; QString TRANSLATIONSDIR; QString THEMESDIR; - explicit MainApplication(const QList &cmdActions, int &argc, char **argv); + explicit MainApplication(const QList &cmdActions, int &argc, char** argv); - enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing, ReloadSettings, HistoryStateChanged, BookmarksChanged }; + enum MessageType { SetAdBlockIconEnabled, CheckPrivateBrowsing, ReloadSettings, HistoryStateChanged, BookmarksChanged }; void connectDatabase(); void loadSettings(); void reloadSettings() { loadSettings(); emit message(ReloadSettings, true); } bool restoreStateSlot(QupZilla* window); - void makeNewWindow(bool tryRestore, const QUrl &startUrl=QUrl()); + void makeNewWindow(bool tryRestore, const QUrl &startUrl = QUrl()); void addNewTab(const QUrl &url = QUrl()); void aboutToCloseWindow(QupZilla* window); bool isStateChanged(); diff --git a/src/app/profileupdater.cpp b/src/app/profileupdater.cpp index 1c29fb763..8f97c0d6b 100644 --- a/src/app/profileupdater.cpp +++ b/src/app/profileupdater.cpp @@ -44,8 +44,10 @@ void ProfileUpdater::checkProfile() versionFile.remove(); updateProfile(QupZilla::VERSION, profileVersion.trimmed()); - } else + } + else { copyDataToProfile(); + } versionFile.open(QFile::WriteOnly); versionFile.write(QupZilla::VERSION.toAscii()); @@ -54,8 +56,9 @@ void ProfileUpdater::checkProfile() void ProfileUpdater::updateProfile(const QString ¤t, const QString &profile) { - if (current == profile) + if (current == profile) { return; + } // Updater::Version currentVersion = Updater::parseVersionFromString(current); Updater::Version profileVersion = Updater::parseVersionFromString(profile); diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index cf17fc862..3264d66ed 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -108,7 +108,7 @@ QupZilla::QupZilla(StartBehaviour behaviour, QUrl startUrl) setupUi(); setupMenu(); QTimer::singleShot(0, this, SLOT(postLaunch())); - connect(mApp, SIGNAL(message(MainApplication::MessageType,bool)), this, SLOT(receiveMessage(MainApplication::MessageType,bool))); + connect(mApp, SIGNAL(message(MainApplication::MessageType, bool)), this, SLOT(receiveMessage(MainApplication::MessageType, bool))); } void QupZilla::postLaunch() @@ -119,43 +119,50 @@ void QupZilla::postLaunch() //Open tab from command line argument bool addTab = true; QStringList arguments = qApp->arguments(); - for (int i = 0;iarguments().count();i++) { + for (int i = 0; i < qApp->arguments().count(); i++) { QString arg = arguments.at(i); if (arg.startsWith("-url=")) { - m_tabWidget->addView(QUrl(arg.replace("-url=",""))); + m_tabWidget->addView(QUrl(arg.replace("-url=", ""))); addTab = false; } } - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-URL-Settings"); - int afterLaunch = settings.value("afterLaunch",1).toInt(); + int afterLaunch = settings.value("afterLaunch", 1).toInt(); settings.endGroup(); settings.beginGroup("SessionRestore"); - bool startingAfterCrash = settings.value("isCrashed",false).toBool(); + bool startingAfterCrash = settings.value("isCrashed", false).toBool(); settings.endGroup(); QUrl startUrl; switch (m_startBehaviour) { case FirstAppWindow: - if (afterLaunch == 0) + if (afterLaunch == 0) { startUrl = QUrl(""); - else if (afterLaunch == 1) + } + else if (afterLaunch == 1) { startUrl = m_homepage; - else + } + else { startUrl = m_homepage; + } - if ( startingAfterCrash || (addTab && afterLaunch == 2) ) + if (startingAfterCrash || (addTab && afterLaunch == 2)) { addTab = !mApp->restoreStateSlot(this); + } break; case NewWindow: - if (afterLaunch == 0) + if (afterLaunch == 0) { startUrl = QUrl(""); - else if (afterLaunch == 1) + } + else if (afterLaunch == 1) { startUrl = m_homepage; - else + } + else { startUrl = m_homepage; + } addTab = true; break; @@ -170,14 +177,16 @@ void QupZilla::postLaunch() addTab = true; } - if (addTab) + if (addTab) { m_tabWidget->addView(startUrl); + } aboutToShowHistoryMenu(false); aboutToShowBookmarksMenu(); - if (m_tabWidget->getTabBar()->normalTabsCount() <= 0) //Something went really wrong .. add one tab + if (m_tabWidget->getTabBar()->normalTabsCount() <= 0) { //Something went really wrong .. add one tab m_tabWidget->addView(m_homepage); + } setUpdatesEnabled(true); emit startingCompleted(); @@ -188,12 +197,13 @@ void QupZilla::setupUi() int locationBarWidth; int websearchBarWidth; - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); settings.beginGroup("Browser-View-Settings"); if (settings.value("WindowMaximised", false).toBool()) { resize(800, 550); setWindowState(Qt::WindowMaximized); - } else { + } + else { setGeometry(settings.value("WindowGeometry", QRect(20, 20, 800, 550)).toRect()); } @@ -204,7 +214,7 @@ void QupZilla::setupUi() setCentralWidget(widget); m_mainLayout = new QVBoxLayout(widget); - m_mainLayout->setContentsMargins(0,0,0,0); + m_mainLayout->setContentsMargins(0, 0, 0, 0); m_mainLayout->setSpacing(0); m_mainSplitter = new QSplitter(this); m_mainSplitter->setObjectName("sidebar-splitter"); @@ -261,7 +271,8 @@ void QupZilla::setupMenu() m_menuFile->addAction(QIcon::fromTheme("document-save"), tr("&Save Page As..."), this, SLOT(savePage()))->setShortcut(QKeySequence("Ctrl+S")); m_menuFile->addAction(tr("Save Page Screen"), this, SLOT(savePageScreen())); m_menuFile->addAction(tr("Send Link..."), this, SLOT(sendLink())); - m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print"), this, SLOT(printPage())); m_menuFile->addSeparator(); + m_menuFile->addAction(QIcon::fromTheme("document-print"), tr("&Print"), this, SLOT(printPage())); + m_menuFile->addSeparator(); m_menuFile->addSeparator(); m_menuFile->addAction(tr("Import bookmarks..."), this, SLOT(showBookmarkImport())); m_menuFile->addAction(QIcon::fromTheme("application-exit"), tr("Quit"), this, SLOT(quitApp()))->setShortcut(QKeySequence("Ctrl+Q")); @@ -362,7 +373,7 @@ void QupZilla::setupMenu() aboutToShowToolsMenu(); aboutToShowHelpMenu(); - m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), this); + m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), this); m_actionRestoreTab->setShortcut(QKeySequence("Ctrl+Shift+T")); connect(m_actionRestoreTab, SIGNAL(triggered()), m_tabWidget, SLOT(restoreClosedTab())); addAction(m_actionRestoreTab); @@ -374,10 +385,11 @@ void QupZilla::setupMenu() // Make shortcuts available even in fullscreen (menu hidden) QList actions = menuBar()->actions(); - foreach (QAction* action, actions) { - if (action->menu()) + foreach(QAction * action, actions) { + if (action->menu()) { actions += action->menu()->actions(); - addAction(action); + } + addAction(action); } m_superMenu->addMenu(m_menuFile); @@ -391,12 +403,12 @@ void QupZilla::setupMenu() void QupZilla::loadSettings() { - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); //Url settings settings.beginGroup("Web-URL-Settings"); - m_homepage = settings.value("homepage","qupzilla:start").toUrl(); - m_newtab = settings.value("newTabUrl","").toUrl(); + m_homepage = settings.value("homepage", "qupzilla:start").toUrl(); + m_newtab = settings.value("newTabUrl", "").toUrl(); settings.endGroup(); QWebSettings* websettings = mApp->webSettings(); @@ -405,14 +417,14 @@ void QupZilla::loadSettings() //Browser Window settings settings.beginGroup("Browser-View-Settings"); m_menuTextColor = settings.value("menuTextColor", QColor(Qt::black)).value(); - bool showStatusBar = settings.value("showStatusBar",true).toBool(); - bool showHomeIcon = settings.value("showHomeButton",true).toBool(); - bool showBackForwardIcons = settings.value("showBackForwardButtons",true).toBool(); - bool showBookmarksToolbar = settings.value("showBookmarksToolbar",true).toBool(); - bool showNavigationToolbar = settings.value("showNavigationToolbar",true).toBool(); - bool showMenuBar = settings.value("showMenubar",true).toBool(); + bool showStatusBar = settings.value("showStatusBar", true).toBool(); + bool showHomeIcon = settings.value("showHomeButton", true).toBool(); + bool showBackForwardIcons = settings.value("showBackForwardButtons", true).toBool(); + bool showBookmarksToolbar = settings.value("showBookmarksToolbar", true).toBool(); + bool showNavigationToolbar = settings.value("showNavigationToolbar", true).toBool(); + bool showMenuBar = settings.value("showMenubar", true).toBool(); bool showAddTab = settings.value("showAddTabButton", false).toBool(); - bool makeTransparent = settings.value("useTransparentBackground",false).toBool(); + bool makeTransparent = settings.value("useTransparentBackground", false).toBool(); m_sideBarWidth = settings.value("SideBarWidth", 250).toInt(); QString activeSideBar = settings.value("SideBar", "None").toString(); settings.endGroup(); @@ -432,18 +444,21 @@ void QupZilla::loadSettings() m_navigationBar->buttonAddTab()->setVisible(showAddTab); if (activeSideBar != "None") { - if (activeSideBar == "Bookmarks") + if (activeSideBar == "Bookmarks") { m_actionShowBookmarksSideBar->trigger(); - else if (activeSideBar == "History") + } + else if (activeSideBar == "History") { m_actionShowHistorySideBar->trigger(); + } } //Private browsing - m_actionPrivateBrowsing->setChecked( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) ); - m_privateBrowsing->setVisible( mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled) ); + m_actionPrivateBrowsing->setChecked(mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)); + m_privateBrowsing->setVisible(mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)); - if (!makeTransparent) + if (!makeTransparent) { return; + } //Opacity #ifdef Q_WS_X11 setAttribute(Qt::WA_TranslucentBackground); @@ -464,10 +479,12 @@ void QupZilla::loadSettings() void QupZilla::setWindowTitle(const QString &t) { - if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { QMainWindow::setWindowTitle(t + tr(" (Private Browsing)")); - else + } + else { QMainWindow::setWindowTitle(t); + } } void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state) @@ -480,10 +497,12 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state) case MainApplication::CheckPrivateBrowsing: m_privateBrowsing->setVisible(state); m_actionPrivateBrowsing->setChecked(state); - if (state) + if (state) { setWindowTitle(windowTitle()); - else + } + else { setWindowTitle(windowTitle().remove(tr(" (Private Browsing)"))); + } break; case MainApplication::ReloadSettings: @@ -508,8 +527,9 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state) void QupZilla::aboutToShowBookmarksMenu() { - if (!m_bookmarksMenuChanged) + if (!m_bookmarksMenuChanged) { return; + } m_bookmarksMenuChanged = false; m_menuBookmarks->clear(); @@ -519,13 +539,13 @@ void QupZilla::aboutToShowBookmarksMenu() m_menuBookmarks->addSeparator(); QSqlQuery query; query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksMenu'"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray()); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } m_menuBookmarks->addAction(icon, title, this, SLOT(loadActionUrl()))->setData(url); } @@ -534,40 +554,42 @@ void QupZilla::aboutToShowBookmarksMenu() folderBookmarks->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon))); query.exec("SELECT title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar'"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray()); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } folderBookmarks->addAction(icon, title, this, SLOT(loadActionUrl()))->setData(url); } - if (folderBookmarks->isEmpty()) + if (folderBookmarks->isEmpty()) { folderBookmarks->addAction(tr("Empty")); + } m_menuBookmarks->addMenu(folderBookmarks); query.exec("SELECT name FROM folders"); - while(query.next()) { + while (query.next()) { QString folderName = query.value(0).toString(); QMenu* tempFolder = new QMenu(folderName, m_menuBookmarks); tempFolder->setIcon(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon))); QSqlQuery query2; query2.exec("SELECT title, url, icon FROM bookmarks WHERE folder='" + folderName + "'"); - while(query2.next()) { + while (query2.next()) { QString title = query2.value(0).toString(); QUrl url = query2.value(1).toUrl(); QIcon icon = IconProvider::iconFromBase64(query2.value(2).toByteArray()); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } tempFolder->addAction(icon, title, this, SLOT(loadActionUrl()))->setData(url); } - if (tempFolder->isEmpty()) + if (tempFolder->isEmpty()) { tempFolder->addAction(tr("Empty")); + } m_menuBookmarks->addMenu(tempFolder); } @@ -575,20 +597,23 @@ void QupZilla::aboutToShowBookmarksMenu() void QupZilla::aboutToShowHistoryMenu(bool loadHistory) { - if (!weView()) + if (!weView()) { return; + } if (!m_historyMenuChanged) { - if (!m_menuHistory || m_menuHistory->actions().count() < 3) + if (!m_menuHistory || m_menuHistory->actions().count() < 3) { return; + } m_menuHistory->actions().at(0)->setEnabled(WebHistoryWrapper::canGoBack(weView()->history())); m_menuHistory->actions().at(1)->setEnabled(WebHistoryWrapper::canGoForward(weView()->history())); return; } m_historyMenuChanged = false; - if (!loadHistory) + if (!loadHistory) { m_historyMenuChanged = true; + } m_menuHistory->clear(); m_menuHistory->addAction(IconProvider::standardIcon(QStyle::SP_ArrowBack), tr("&Back"), this, SLOT(goBack()))->setShortcut(QKeySequence("Ctrl+Left")); @@ -598,18 +623,18 @@ void QupZilla::aboutToShowHistoryMenu(bool loadHistory) m_menuHistory->actions().at(0)->setEnabled(WebHistoryWrapper::canGoBack(weView()->history())); m_menuHistory->actions().at(1)->setEnabled(WebHistoryWrapper::canGoForward(weView()->history())); - m_menuHistory->addAction(QIcon(":/icons/menu/history.png"), tr("Show &All History"), this, SLOT(showHistoryManager())); + m_menuHistory->addAction(QIcon(":/icons/menu/history.png"), tr("Show &All History"), this, SLOT(showHistoryManager()))->setShortcut(QKeySequence("Ctrl+Shift+H")); m_menuHistory->addSeparator(); if (loadHistory) { QSqlQuery query; query.exec("SELECT title, url FROM history ORDER BY date DESC LIMIT 10"); - while(query.next()) { + while (query.next()) { QUrl url = query.value(1).toUrl(); QString title = query.value(0).toString(); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } m_menuHistory->addAction(_iconForUrl(url), title, this, SLOT(loadActionUrl()))->setData(url); } @@ -620,8 +645,9 @@ void QupZilla::aboutToShowHistoryMenu(bool loadHistory) void QupZilla::aboutToHideHistoryMenu() { - if (!m_menuHistory || m_menuHistory->actions().count() < 3) + if (!m_menuHistory || m_menuHistory->actions().count() < 3) { return; + } m_menuHistory->actions().at(0)->setEnabled(true); m_menuHistory->actions().at(1)->setEnabled(true); @@ -631,18 +657,19 @@ void QupZilla::aboutToShowClosedTabsMenu() { m_menuClosedTabs->clear(); int i = 0; - foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) { + foreach(ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) { QString title = tab.title; - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } m_menuClosedTabs->addAction(_iconForUrl(tab.url), title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i); i++; } m_menuClosedTabs->addSeparator(); - if (i == 0) + if (i == 0) { m_menuClosedTabs->addAction(tr("Empty"))->setEnabled(false); + } else { m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs())); m_menuClosedTabs->addAction(tr("Clear list"), m_tabWidget, SLOT(clearClosedTabsList())); @@ -657,7 +684,11 @@ void QupZilla::aboutToShowHelpMenu() m_menuHelp->addAction(QIcon(":/icons/menu/qt.png"), tr("About &Qt"), qApp, SLOT(aboutQt())); m_menuHelp->addAction(QIcon(":/icons/qupzilla.png"), tr("&About QupZilla"), this, SLOT(aboutQupZilla())); m_menuHelp->addSeparator(); - m_menuHelp->addAction(QIcon(":/icons/menu/informations.png"), tr("Informations about application"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:about")); + QAction* infoAction = new QAction(QIcon(":/icons/menu/informations.png"), tr("Informations about application"), m_menuHelp); + infoAction->setData(QUrl("qupzilla:about")); + infoAction->setShortcut(QKeySequence(QKeySequence::HelpContents)); + connect(infoAction, SIGNAL(triggered()), this, SLOT(loadActionUrlInNewTab())); + m_menuHelp->addAction(infoAction); m_menuHelp->addAction(tr("Report &Issue"), this, SLOT(loadActionUrlInNewTab()))->setData(QUrl("qupzilla:reportbug")); } @@ -685,8 +716,9 @@ void QupZilla::aboutToShowToolsMenu() void QupZilla::aboutToShowViewMenu() { - if (!weView()) + if (!weView()) { return; + } if (weView()->isLoading()) { m_actionStop->setEnabled(true); @@ -706,7 +738,8 @@ void QupZilla::aboutToShowViewMenu() m_actionShowBookmarksSideBar->setChecked(false); m_actionShowHistorySideBar->setChecked(false); // m_actionShowRssSideBar->setChecked(false); - } else { + } + else { SideBar::SideWidget actWidget = m_sideBar->activeWidget(); m_actionShowBookmarksSideBar->setChecked(actWidget == SideBar::Bookmarks); m_actionShowHistorySideBar->setChecked(actWidget == SideBar::History); @@ -720,9 +753,10 @@ void QupZilla::aboutToHideViewMenu() m_actionStop->setEnabled(true); if (m_mainLayout->count() == 4) { - SearchToolBar* search = qobject_cast( m_mainLayout->itemAt(3)->widget() ); - if (!search) + SearchToolBar* search = qobject_cast(m_mainLayout->itemAt(3)->widget()); + if (!search) { return; + } m_actionStop->setEnabled(false); } } @@ -740,41 +774,54 @@ void QupZilla::aboutToShowEncodingMenu() qSort(available); QString activeCodec = mApp->webSettings()->defaultTextEncoding(); - foreach (QByteArray name, available) { - if (QTextCodec::codecForName(name)->aliases().contains(name)) + foreach(QByteArray name, available) { + if (QTextCodec::codecForName(name)->aliases().contains(name)) { continue; - QAction* action = new QAction(name=="System" ? tr("Default") : name, this); + } + QAction* action = new QAction(name == "System" ? tr("Default") : name, this); action->setData(name); action->setCheckable(true); connect(action, SIGNAL(triggered()), this, SLOT(changeEncoding())); - if (activeCodec.compare(name, Qt::CaseInsensitive) == 0) + if (activeCodec.compare(name, Qt::CaseInsensitive) == 0) { action->setChecked(true); + } - if (name.startsWith("ISO")) + if (name.startsWith("ISO")) { menuISO->addAction(action); - else if (name.startsWith("UTF")) + } + else if (name.startsWith("UTF")) { menuUTF->addAction(action); - else if (name.startsWith("windows")) + } + else if (name.startsWith("windows")) { menuWindows->addAction(action); - else if (name.startsWith("Iscii")) + } + else if (name.startsWith("Iscii")) { menuIscii->addAction(action); - else if (name == "System") + } + else if (name == "System") { m_menuEncoding->addAction(action); - else + } + else { menuOther->addAction(action); + } } m_menuEncoding->addSeparator(); - if (!menuISO->isEmpty()) + if (!menuISO->isEmpty()) { m_menuEncoding->addMenu(menuISO); - if (!menuUTF->isEmpty()) + } + if (!menuUTF->isEmpty()) { m_menuEncoding->addMenu(menuUTF); - if (!menuWindows->isEmpty()) + } + if (!menuWindows->isEmpty()) { m_menuEncoding->addMenu(menuWindows); - if (!menuIscii->isEmpty()) + } + if (!menuIscii->isEmpty()) { m_menuEncoding->addMenu(menuIscii); - if (!menuOther->isEmpty()) + } + if (!menuOther->isEmpty()) { m_menuEncoding->addMenu(menuOther); + } } void QupZilla::changeEncoding() @@ -832,8 +879,9 @@ void QupZilla::loadAddress(const QUrl &url) void QupZilla::urlEnter() { - if (locationBar()->text().isEmpty()) + if (locationBar()->text().isEmpty()) { return; + } loadAddress(QUrl(WebView::guessUrlFromString(locationBar()->text()))); weView()->setFocus(); } @@ -896,7 +944,7 @@ void QupZilla::showBookmarksToolbar() bool status = m_bookmarksToolbar->isVisible(); m_bookmarksToolbar->setVisible(!status); - QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat); + QSettings settings(activeProfil() + "settings.ini", QSettings::IniFormat); settings.setValue("Browser-View-Settings/showBookmarksToolbar", !status); } @@ -904,8 +952,9 @@ void QupZilla::showBookmarksSideBar() { addSideBar(); - if (m_sideBar->activeWidget() != SideBar::Bookmarks) + if (m_sideBar->activeWidget() != SideBar::Bookmarks) { m_sideBar->showBookmarks(); + } else { m_sideBar->close(); } @@ -915,8 +964,9 @@ void QupZilla::showHistorySideBar() { addSideBar(); - if (m_sideBar->activeWidget() != SideBar::History) + if (m_sideBar->activeWidget() != SideBar::History) { m_sideBar->showHistory(); + } else { m_sideBar->close(); } @@ -924,8 +974,9 @@ void QupZilla::showHistorySideBar() void QupZilla::addSideBar() { - if (m_sideBar) + if (m_sideBar) { return; + } m_sideBar = new SideBar(this); @@ -946,25 +997,27 @@ void QupZilla::saveSideBarWidth() void QupZilla::showNavigationToolbar() { - if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked()) + if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked()) { showMenubar(); + } bool status = m_navigationBar->isVisible(); m_navigationBar->setVisible(!status); - QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat); + QSettings settings(activeProfil() + "settings.ini", QSettings::IniFormat); settings.setValue("Browser-View-Settings/showNavigationToolbar", !status); } void QupZilla::showMenubar() { - if (!m_navigationBar->isVisible() && !m_actionShowMenubar->isChecked()) + if (!m_navigationBar->isVisible() && !m_actionShowMenubar->isChecked()) { showNavigationToolbar(); + } menuBar()->setVisible(!menuBar()->isVisible()); m_navigationBar->buttonSuperMenu()->setVisible(!menuBar()->isVisible()); - QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat); + QSettings settings(activeProfil() + "settings.ini", QSettings::IniFormat); settings.setValue("Browser-View-Settings/showMenubar", menuBar()->isVisible()); } @@ -973,7 +1026,7 @@ void QupZilla::showStatusbar() bool status = statusBar()->isVisible(); statusBar()->setVisible(!status); - QSettings settings(activeProfil()+"settings.ini", QSettings::IniFormat); + QSettings settings(activeProfil() + "settings.ini", QSettings::IniFormat); settings.setValue("Browser-View-Settings/showStatusbar", !status); } @@ -1020,9 +1073,10 @@ void QupZilla::webSearch() void QupZilla::searchOnPage() { if (m_mainLayout->count() == 4) { - SearchToolBar* search = qobject_cast( m_mainLayout->itemAt(3)->widget() ); - if (!search) + SearchToolBar* search = qobject_cast(m_mainLayout->itemAt(3)->widget()); + if (!search) { return; + } search->searchLine()->setFocus(); return; @@ -1036,25 +1090,30 @@ void QupZilla::searchOnPage() void QupZilla::openFile() { QString filePath = QFileDialog::getOpenFileName(this, tr("Open file..."), QDir::homePath(), "(*.html *.htm *.jpg *.png)"); - if (!filePath.isEmpty()) + if (!filePath.isEmpty()) { loadAddress(QUrl(filePath)); + } } void QupZilla::showNavigationWithFullscreen() { bool state; - if (m_navigationVisible) + if (m_navigationVisible) { state = !m_navigationBar->isVisible(); - else + } + else { state = !m_tabWidget->getTabBar()->isVisible(); + } - if (m_navigationVisible) + if (m_navigationVisible) { m_navigationBar->setVisible(state); + } m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(state); - if (m_bookmarksToolBarVisible) + if (m_bookmarksToolBarVisible) { m_bookmarksToolbar->setVisible(state); + } } void QupZilla::fullScreen(bool make) @@ -1122,14 +1181,15 @@ void QupZilla::startPrivate(bool state) actions.append(tr("Your session is not stored.")); QString text2 = tr("Until you close the window, you can still click the Back and Forward " - "buttons to return to the webpages you have opened."); + "buttons to return to the webpages you have opened."); QString message = QString(QLatin1String("%1

%2

  • %3

%4

")).arg(title, text1, actions.join(QLatin1String("
  • ")), text2); QMessageBox::StandardButton button = QMessageBox::question(this, tr("Start Private Browsing"), - message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - if (button != QMessageBox::Yes) + message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (button != QMessageBox::Yes) { return; + } } mApp->webSettings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, state); mApp->history()->setSaving(!state); @@ -1137,7 +1197,7 @@ void QupZilla::startPrivate(bool state) emit message(MainApplication::CheckPrivateBrowsing, state); } -void QupZilla::keyPressEvent(QKeyEvent *event) +void QupZilla::keyPressEvent(QKeyEvent* event) { switch (event->key()) { case Qt::Key_Back: @@ -1213,8 +1273,9 @@ void QupZilla::mousePressEvent(QMouseEvent* event) void QupZilla::closeEvent(QCloseEvent* event) { - if (mApp->isClosing()) + if (mApp->isClosing()) { return; + } m_isClosing = true; mApp->saveStateSlot(); @@ -1230,11 +1291,12 @@ void QupZilla::closeEvent(QCloseEvent* event) bool QupZilla::quitApp() { - if (m_sideBar) + if (m_sideBar) { saveSideBarWidth(); + } - QSettings settings(m_activeProfil+"settings.ini", QSettings::IniFormat); - int afterLaunch = settings.value("Web-URL-Settings/afterLaunch",0).toInt(); + QSettings settings(m_activeProfil + "settings.ini", QSettings::IniFormat); + int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 0).toInt(); bool askOnClose = settings.value("Browser-Tabs-Settings/AskOnClosing", false).toBool(); settings.beginGroup("Browser-View-Settings"); @@ -1250,10 +1312,12 @@ bool QupZilla::quitApp() ui->setupUi(dialog); ui->textLabel->setText(tr("There are still %1 open tabs and your session won't be stored. Are you sure to quit?").arg(m_tabWidget->count())); ui->iconLabel->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning)); - if (dialog->exec() != QDialog::Accepted) + if (dialog->exec() != QDialog::Accepted) { return false; - if (ui->dontAskAgain->isChecked()) + } + if (ui->dontAskAgain->isChecked()) { settings.setValue("Browser-Tabs-Settings/AskOnClosing", false); + } } mApp->quitApplication(); @@ -1269,6 +1333,7 @@ QupZilla::~QupZilla() delete m_bookmarksToolbar; delete m_progressBar; - if (m_webInspectorDock) + if (m_webInspectorDock) { delete m_webInspectorDock; + } } diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index a023b9a4c..9af9c8d33 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -98,10 +98,10 @@ public: inline StatusBarMessage* statusBarMessage() { return m_statusBarMessage; } inline NavigationBar* navigationBar() { return m_navigationBar; } - inline ProgressBar* progressBar(){ return m_progressBar; } - inline QString activeProfil(){ return m_activeProfil; } - inline QString activeLanguage(){ return m_activeLanguage; } - inline QLabel* ipLabel(){ return m_ipLabel; } + inline ProgressBar* progressBar() { return m_progressBar; } + inline QString activeProfil() { return m_activeProfil; } + inline QString activeLanguage() { return m_activeLanguage; } + inline QLabel* ipLabel() { return m_ipLabel; } inline QColor menuTextColor() { return m_menuTextColor; } inline QMenu* menuHelp() { return m_menuHelp; } inline QAction* actionRestoreTab() { return m_actionRestoreTab; } @@ -126,7 +126,7 @@ public slots: void loadActionUrlInNewTab(); void bookmarkPage(); void loadAddress(const QUrl &url); - void showSource(const QString& selectedHtml = ""); + void showSource(const QString &selectedHtml = ""); void showPageInfo(); void receiveMessage(MainApplication::MessageType mes, bool state); @@ -177,7 +177,7 @@ private slots: void openLocation() { locationBar()->setFocus(); locationBar()->selectAll(); } void openFile(); void savePage(); - void sendLink() { QDesktopServices::openUrl(QUrl("mailto:?body="+weView()->url().toString())); } + void sendLink() { QDesktopServices::openUrl(QUrl("mailto:?body=" + weView()->url().toString())); } void webSearch(); void copy() { QApplication::clipboard()->setText(weView()->selectedText()); } @@ -193,7 +193,7 @@ private slots: bool quitApp(); private: - void keyPressEvent(QKeyEvent *event); + void keyPressEvent(QKeyEvent* event); void mousePressEvent(QMouseEvent* event); void closeEvent(QCloseEvent* event); diff --git a/src/autofill/autofillmodel.cpp b/src/autofill/autofillmodel.cpp index 791b19069..f0ec3b225 100644 --- a/src/autofill/autofillmodel.cpp +++ b/src/autofill/autofillmodel.cpp @@ -23,15 +23,15 @@ AutoFillModel::AutoFillModel(QupZilla* mainClass, QObject* parent) : QObject(parent) - ,p_QupZilla(mainClass) - ,m_isStoring(false) + , p_QupZilla(mainClass) + , m_isStoring(false) { QTimer::singleShot(0, this, SLOT(loadSettings())); } void AutoFillModel::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); m_isStoring = settings.value("SavePasswordsOnSites", true).toBool(); settings.endGroup(); @@ -39,44 +39,48 @@ void AutoFillModel::loadSettings() bool AutoFillModel::isStored(const QUrl &url) { - if (!isStoringEnabled(url)) + if (!isStoringEnabled(url)) { return false; + } QString server = url.host(); QSqlQuery query; - query.exec("SELECT count(id) FROM autofill WHERE server='"+server+"'"); + query.exec("SELECT count(id) FROM autofill WHERE server='" + server + "'"); query.next(); - if (query.value(0).toInt()>0) + if (query.value(0).toInt() > 0) { return true; + } return false; } bool AutoFillModel::isStoringEnabled(const QUrl &url) { - if (!m_isStoring) + if (!m_isStoring) { return false; + } QString server = url.host(); QSqlQuery query; - query.exec("SELECT count(id) FROM autofill_exceptions WHERE server='"+server+"'"); + query.exec("SELECT count(id) FROM autofill_exceptions WHERE server='" + server + "'"); query.next(); - if (query.value(0).toInt()>0) + if (query.value(0).toInt() > 0) { return false; + } return true; } -void AutoFillModel::blockStoringfor (const QUrl &url) +void AutoFillModel::blockStoringfor(const QUrl &url) { QString server = url.host(); QSqlQuery query; - query.exec("INSERT INTO autofill_exceptions (server) VALUES ('"+server+"')"); + query.exec("INSERT INTO autofill_exceptions (server) VALUES ('" + server + "')"); } QString AutoFillModel::getUsername(const QUrl &url) { QString server = url.host(); QSqlQuery query; - query.exec("SELECT username FROM autofill WHERE server='"+server+"'"); + query.exec("SELECT username FROM autofill WHERE server='" + server + "'"); query.next(); return query.value(0).toString(); } @@ -85,7 +89,7 @@ QString AutoFillModel::getPassword(const QUrl &url) { QString server = url.host(); QSqlQuery query; - query.exec("SELECT password FROM autofill WHERE server='"+server+"'"); + query.exec("SELECT password FROM autofill WHERE server='" + server + "'"); query.next(); return query.value(0).toString(); } @@ -94,9 +98,10 @@ QString AutoFillModel::getPassword(const QUrl &url) bool AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString &pass) { QSqlQuery query; - query.exec("SELECT username FROM autofill WHERE server='"+url.host()+"'"); - if (query.next()) + query.exec("SELECT username FROM autofill WHERE server='" + url.host() + "'"); + if (query.next()) { return false; + } query.prepare("INSERT INTO autofill (server, username, password) VALUES (?,?,?)"); query.bindValue(0, url.host()); query.bindValue(1, name); @@ -108,9 +113,10 @@ bool AutoFillModel::addEntry(const QUrl &url, const QString &name, const QString bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QString &pass) { QSqlQuery query; - query.exec("SELECT data FROM autofill WHERE server='"+url.host()+"'"); - if (query.next()) + query.exec("SELECT data FROM autofill WHERE server='" + url.host() + "'"); + if (query.next()) { return false; + } query.prepare("INSERT INTO autofill (server, data, password) VALUES (?,?,?)"); query.bindValue(0, url.host()); @@ -121,8 +127,9 @@ bool AutoFillModel::addEntry(const QUrl &url, const QByteArray &data, const QStr void AutoFillModel::completePage(WebView* view) { - if (!isStored(view->url())) + if (!isStored(view->url())) { return; + } QWebElementCollection inputs; QList frames; @@ -134,26 +141,29 @@ void AutoFillModel::completePage(WebView* view) } QSqlQuery query; - query.exec("SELECT data FROM autofill WHERE server='"+view->url().host()+"'"); + query.exec("SELECT data FROM autofill WHERE server='" + view->url().host() + "'"); query.next(); QByteArray data = query.value(0).toByteArray(); - if (data.isEmpty()) + if (data.isEmpty()) { return; + } - QList > arguments = QUrl::fromEncoded(QByteArray("http://bla.com/?"+data)).queryItems(); - for (int i = 0; i > arguments = QUrl::fromEncoded(QByteArray("http://bla.com/?" + data)).queryItems(); + for (int i = 0; i < arguments.count(); i++) { QString key = QUrl::fromEncoded(arguments.at(i).first.toAscii()).toString(); QString value = QUrl::fromEncoded(arguments.at(i).second.toAscii()).toString(); //key.replace("+"," "); //value.replace("+"," "); - for (int i = 0; iwebSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { return; + } m_lastOutgoingData = outgoingData; @@ -170,14 +181,16 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo QWebPage* webPage = (QWebPage*)(v.value()); v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102)); WebView* webView = (WebView*)(v.value()); - if (!webPage || !webView) + if (!webPage || !webView) { return; + } v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101)); QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt(); - if (type!=QWebPage::NavigationTypeFormSubmitted) + if (type != QWebPage::NavigationTypeFormSubmitted) { return; + } QString passwordName = ""; QString passwordValue = ""; @@ -192,20 +205,23 @@ void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgo frames += frame->childFrames(); } - foreach (QWebElement element, inputs) { + foreach(QWebElement element, inputs) { passwordName = element.attribute("name"); passwordValue = element.evaluateJavaScript("this.value").toString(); - if (!passwordValue.isEmpty()) + if (!passwordValue.isEmpty()) { break; + } } //Return if storing is not enabled, data for this page is already stored, no password element found in sent data - if (passwordName.isEmpty() || !isStoringEnabled(siteUrl) || isStored(siteUrl)) + if (passwordName.isEmpty() || !isStoringEnabled(siteUrl) || isStored(siteUrl)) { return; + } //Return if no password form has been sent - if (!outgoingData.contains((QUrl(passwordName).toEncoded() + "=")) || passwordValue.isEmpty()) + if (!outgoingData.contains((QUrl(passwordName).toEncoded() + "=")) || passwordValue.isEmpty()) { return; + } AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, outgoingData, passwordValue); webView->addNotification(aWidget); diff --git a/src/autofill/autofillmodel.h b/src/autofill/autofillmodel.h index dca78aec5..077c442f8 100644 --- a/src/autofill/autofillmodel.h +++ b/src/autofill/autofillmodel.h @@ -33,7 +33,7 @@ public: bool isStored(const QUrl &url); bool isStoringEnabled(const QUrl &url); - void blockStoringfor (const QUrl &url); + void blockStoringfor(const QUrl &url); QString getUsername(const QUrl &url); QString getPassword(const QUrl &url); diff --git a/src/autofill/autofillnotification.cpp b/src/autofill/autofillnotification.cpp index e4bd6a435..355de1ef7 100644 --- a/src/autofill/autofillnotification.cpp +++ b/src/autofill/autofillnotification.cpp @@ -23,11 +23,11 @@ #include "iconprovider.h" AutoFillNotification::AutoFillNotification(QUrl url, QByteArray data, QString pass, QWidget* parent) - :AnimatedWidget(AnimatedWidget::Down, 300, parent) - ,ui(new Ui::AutoFillWidget) - ,m_url(url) - ,m_data(data) - ,m_pass(pass) + : AnimatedWidget(AnimatedWidget::Down, 300, parent) + , ui(new Ui::AutoFillWidget) + , m_url(url) + , m_data(data) + , m_pass(pass) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(widget()); diff --git a/src/autofill/autofillnotification.h b/src/autofill/autofillnotification.h index 390d116ff..edd3a47f0 100644 --- a/src/autofill/autofillnotification.h +++ b/src/autofill/autofillnotification.h @@ -25,8 +25,9 @@ #include "animatedwidget.h" -namespace Ui { - class AutoFillWidget; +namespace Ui +{ +class AutoFillWidget; } class AnimatedWidget; class AutoFillNotification : public AnimatedWidget diff --git a/src/bookmarks/bookmarkicon.cpp b/src/bookmarks/bookmarkicon.cpp index ed400395f..77e7e9183 100644 --- a/src/bookmarks/bookmarkicon.cpp +++ b/src/bookmarks/bookmarkicon.cpp @@ -44,33 +44,40 @@ void BookmarkIcon::iconClicked() if (m_bookmarksModel->isBookmarked(url)) { BookmarksWidget* menu = new BookmarksWidget(m_bookmarksModel->bookmarkId(url), p_QupZilla->locationBar()); menu->showAt(this); - } else + } + else { m_bookmarksModel->saveBookmark(p_QupZilla->weView()); + } } void BookmarkIcon::checkBookmark(const QUrl &url) { - if (m_lastUrl == url) + if (m_lastUrl == url) { return; + } - if (m_bookmarksModel->isBookmarked(url)) + if (m_bookmarksModel->isBookmarked(url)) { setBookmarkSaved(); - else + } + else { setBookmarkDisabled(); + } m_lastUrl = url; } void BookmarkIcon::bookmarkDeleted(const BookmarksModel::Bookmark &bookmark) { - if (bookmark.url == m_lastUrl) + if (bookmark.url == m_lastUrl) { setBookmarkDisabled(); + } } void BookmarkIcon::bookmarkAdded(const BookmarksModel::Bookmark &bookmark) { - if (bookmark.url == m_lastUrl) + if (bookmark.url == m_lastUrl) { setBookmarkSaved(); + } } void BookmarkIcon::setBookmarkSaved() diff --git a/src/bookmarks/bookmarksmanager.cpp b/src/bookmarks/bookmarksmanager.cpp index a61686da5..c75293379 100644 --- a/src/bookmarks/bookmarksmanager.cpp +++ b/src/bookmarks/bookmarksmanager.cpp @@ -40,7 +40,7 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent) ui->deleteB->setShortcut(QKeySequence("Del")); connect(ui->deleteB, SIGNAL(clicked()), this, SLOT(deleteItem())); - connect(ui->bookmarksTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*))); + connect(ui->bookmarksTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*))); connect(ui->addSubfolder, SIGNAL(clicked()), this, SLOT(addSubfolder())); connect(ui->addFolder, SIGNAL(clicked()), this, SLOT(addFolder())); connect(ui->renameFolder, SIGNAL(clicked()), this, SLOT(renameFolder())); @@ -50,11 +50,11 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent) connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(addBookmark(BookmarksModel::Bookmark))); connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(removeBookmark(BookmarksModel::Bookmark))); - connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark))); + connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark))); connect(m_bookmarksModel, SIGNAL(subfolderAdded(QString)), this, SLOT(addSubfolder(QString))); connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString))); connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString))); - connect(m_bookmarksModel, SIGNAL(folderRenamed(QString,QString)), this, SLOT(renameFolder(QString,QString))); + connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString))); connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb())); @@ -70,22 +70,25 @@ void BookmarksManager::search(const QString &string) QupZilla* BookmarksManager::getQupZilla() { - if (!p_QupZilla) + if (!p_QupZilla) { p_QupZilla = mApp->getWindow(); + } return p_QupZilla; } void BookmarksManager::setMainWindow(QupZilla* window) { - if (window) + if (window) { p_QupZilla = window; + } } void BookmarksManager::addFolder() { QString text = QInputDialog::getText(this, tr("Add new folder"), tr("Choose name for new bookmark folder: ")); - if (text.isEmpty()) + if (text.isEmpty()) { return; + } m_bookmarksModel->createFolder(text); } @@ -93,8 +96,9 @@ void BookmarksManager::addFolder() void BookmarksManager::addSubfolder() { QString text = QInputDialog::getText(this, tr("Add new subfolder"), tr("Choose name for new subfolder in bookmarks toolbar: ")); - if (text.isEmpty()) + if (text.isEmpty()) { return; + } m_bookmarksModel->createSubfolder(text); } @@ -102,28 +106,33 @@ void BookmarksManager::addSubfolder() void BookmarksManager::renameFolder() { QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) + if (!item) { return; + } - if (!item->text(1).isEmpty()) + if (!item->text(1).isEmpty()) { return; + } QString folder = item->text(0); - if (folder == tr("Bookmarks In Menu") || folder == tr("Bookmarks In ToolBar")) + if (folder == tr("Bookmarks In Menu") || folder == tr("Bookmarks In ToolBar")) { return; + } QString text = QInputDialog::getText(this, tr("Rename Folder"), tr("Choose name for folder: "), QLineEdit::Normal, folder); - if (text.isEmpty()) + if (text.isEmpty()) { return; + } m_bookmarksModel->renameFolder(folder, text); } void BookmarksManager::itemChanged(QTreeWidgetItem* item) { - if (!item || m_isRefreshing || item->text(1).isEmpty()) + if (!item || m_isRefreshing || item->text(1).isEmpty()) { return; + } QString name = item->text(0); QUrl url = QUrl(item->text(1)); @@ -135,22 +144,25 @@ void BookmarksManager::itemChanged(QTreeWidgetItem* item) void BookmarksManager::itemControlClicked(QTreeWidgetItem* item) { - if (!item || item->text(1).isEmpty()) + if (!item || item->text(1).isEmpty()) { return; + } getQupZilla()->tabWidget()->addView(QUrl(item->text(1))); } void BookmarksManager::loadInNewTab() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { getQupZilla()->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab); + } } void BookmarksManager::deleteItem() { QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) + if (!item) { return; + } if (item->text(1).isEmpty()) { // Delete folder QString folder = item->text(0); @@ -170,8 +182,9 @@ void BookmarksManager::addBookmark(WebView* view) void BookmarksManager::moveBookmark() { QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) + if (!item) { return; + } if (QAction* action = qobject_cast(sender())) { m_bookmarksModel->editBookmark(item->whatsThis(1).toInt(), item->text(0), QUrl(), action->data().toString()); } @@ -179,11 +192,13 @@ void BookmarksManager::moveBookmark() void BookmarksManager::contextMenuRequested(const QPoint &position) { - if (!ui->bookmarksTree->itemAt(position)) + if (!ui->bookmarksTree->itemAt(position)) { return; + } QString link = ui->bookmarksTree->itemAt(position)->text(1); - if (link.isEmpty()) + if (link.isEmpty()) { return; + } QMenu menu; menu.addAction(tr("Open link in actual &tab"), getQupZilla(), SLOT(loadActionUrl()))->setData(link); @@ -197,13 +212,14 @@ void BookmarksManager::contextMenuRequested(const QPoint &position) moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"), this, SLOT(moveBookmark()))->setData("bookmarksToolbar"); QSqlQuery query; query.exec("SELECT name FROM folders"); - while(query.next()) + while (query.next()) { moveMenu.addAction(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), this, SLOT(moveBookmark()))->setData(query.value(0).toString()); + } menu.addMenu(&moveMenu); //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu.exec(p); } @@ -225,7 +241,7 @@ void BookmarksManager::refreshTable() ui->bookmarksTree->addTopLevelItem(bookmarksToolbar); query.exec("SELECT name FROM folders WHERE subfolder!='yes'"); - while(query.next()) { + while (query.next()) { newItem = new QTreeWidgetItem(ui->bookmarksTree); newItem->setText(0, query.value(0).toString()); newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); @@ -233,22 +249,25 @@ void BookmarksManager::refreshTable() } query.exec("SELECT title, url, id, folder, icon FROM bookmarks"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); int id = query.value(2).toInt(); QString folder = query.value(3).toString(); QIcon icon = IconProvider::iconFromBase64(query.value(4).toByteArray()); QTreeWidgetItem* item = new QTreeWidgetItem(); - if (folder == "bookmarksMenu") + if (folder == "bookmarksMenu") { folder = tr("Bookmarks In Menu"); - if (folder == "bookmarksToolbar") + } + if (folder == "bookmarksToolbar") { folder = tr("Bookmarks In ToolBar"); + } if (folder != "unsorted") { QList findParent = ui->bookmarksTree->findItems(folder, 0); - if (findParent.count() != 1) + if (findParent.count() != 1) { continue; + } findParent.at(0)->addChild(item); } @@ -264,7 +283,7 @@ void BookmarksManager::refreshTable() } query.exec("SELECT name FROM folders WHERE subfolder='yes'"); - while(query.next()) { + while (query.next()) { newItem = new QTreeWidgetItem(bookmarksToolbar); newItem->setText(0, query.value(0).toString()); newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); @@ -273,7 +292,7 @@ void BookmarksManager::refreshTable() query2.prepare("SELECT title, url, id, icon FROM bookmarks WHERE folder=?"); query2.addBindValue(query.value(0).toString()); query2.exec(); - while(query2.next()) { + while (query2.next()) { QString title = query2.value(0).toString(); QUrl url = query2.value(1).toUrl(); int id = query2.value(2).toInt(); @@ -313,7 +332,7 @@ void BookmarksManager::addBookmark(const BookmarksModel::Bookmark &bookmark) if (bookmark.inSubfolder) { QList list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive); if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { + foreach(QTreeWidgetItem * it, list) { if (it->text(1).isEmpty()) { it->addChild(item); break; @@ -321,10 +340,12 @@ void BookmarksManager::addBookmark(const BookmarksModel::Bookmark &bookmark) } } } - else if (bookmark.folder != "unsorted") + else if (bookmark.folder != "unsorted") { ui->bookmarksTree->appendToParentItem(translatedFolder, item); - else + } + else { ui->bookmarksTree->addTopLevelItem(item); + } m_isRefreshing = false; } @@ -336,20 +357,22 @@ void BookmarksManager::removeBookmark(const BookmarksModel::Bookmark &bookmark) QList list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive); QTreeWidgetItem* subfolderItem = 0; if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { + foreach(QTreeWidgetItem * it, list) { if (it->text(1).isEmpty()) { subfolderItem = it; break; } } } - if (!subfolderItem) + if (!subfolderItem) { return; + } for (int i = 0; i < subfolderItem->childCount(); i++) { QTreeWidgetItem* item = subfolderItem->child(i); - if (!item) + if (!item) { continue; + } if (item->text(0) == bookmark.title && item->whatsThis(1) == QString::number(bookmark.id)) { ui->bookmarksTree->deleteItem(item); return; @@ -358,23 +381,28 @@ void BookmarksManager::removeBookmark(const BookmarksModel::Bookmark &bookmark) } else if (bookmark.folder == "unsorted") { QList list = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* item = list.at(0); - if (item && item->whatsThis(1) == QString::number(bookmark.id)) + if (item && item->whatsThis(1) == QString::number(bookmark.id)) { ui->bookmarksTree->deleteItem(item); + } } else { QList list = ui->bookmarksTree->findItems(BookmarksModel::toTranslatedFolder(bookmark.folder), Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* parentItem = list.at(0); - if (!parentItem) + if (!parentItem) { return; + } for (int i = 0; i < parentItem->childCount(); i++) { QTreeWidgetItem* item = parentItem->child(i); - if (!item) + if (!item) { continue; + } if (item->text(0) == bookmark.title && item->whatsThis(1) == QString::number(bookmark.id)) { ui->bookmarksTree->deleteItem(item); return; @@ -418,20 +446,22 @@ void BookmarksManager::addSubfolder(const QString &name) void BookmarksManager::removeFolder(const QString &name) { QList list = ui->bookmarksTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* folderItem = 0; if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { + foreach(QTreeWidgetItem * it, list) { if (it->text(1).isEmpty()) { folderItem = it; break; } } } - if (!folderItem) + if (!folderItem) { return; + } ui->bookmarksTree->deleteItem(folderItem); } @@ -439,28 +469,31 @@ void BookmarksManager::removeFolder(const QString &name) void BookmarksManager::renameFolder(const QString &before, const QString &after) { QList list = ui->bookmarksTree->findItems(before, Qt::MatchExactly | Qt::MatchRecursive); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* folderItem = 0; if (list.count() != 0) { - foreach (QTreeWidgetItem* it, list) { + foreach(QTreeWidgetItem * it, list) { if (it->text(0) == before && it->text(1).isEmpty()) { folderItem = it; break; } } } - if (!folderItem) + if (!folderItem) { return; + } folderItem->setText(0, after); } void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, const QIcon &icon) { - if (url.isEmpty() || title.isEmpty()) + if (url.isEmpty() || title.isEmpty()) { return; + } QDialog* dialog = new QDialog(getQupZilla()); QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog); QLabel* label = new QLabel(dialog); @@ -474,8 +507,9 @@ void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, con layout->addWidget(label); layout->addWidget(edit); layout->addWidget(combo); - if (m_bookmarksModel->isBookmarked(url)) + if (m_bookmarksModel->isBookmarked(url)) { layout->addWidget(new QLabel(tr("Warning: You already have this page bookmarked!"))); + } layout->addWidget(box); combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks")); @@ -483,8 +517,9 @@ void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, con combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar")); QSqlQuery query; query.exec("SELECT name FROM folders"); - while(query.next()) + while (query.next()) { combo->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString()); + } label->setText(tr("Choose name and location of bookmark.")); edit->setText(title); @@ -496,10 +531,12 @@ void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, con size.setWidth(350); dialog->resize(size); dialog->exec(); - if (dialog->result() == QDialog::Rejected) + if (dialog->result() == QDialog::Rejected) { return; - if (edit->text().isEmpty()) + } + if (edit->text().isEmpty()) { return; + } m_bookmarksModel->saveBookmark(url, edit->text(), icon, BookmarksModel::fromTranslatedFolder(combo->currentText())); delete dialog; @@ -525,8 +562,9 @@ void BookmarksManager::insertAllTabs() combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar")); QSqlQuery query; query.exec("SELECT name FROM folders"); - while(query.next()) + while (query.next()) { combo->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString()); + } label->setText(tr("Choose folder for bookmarks:")); dialog->setWindowTitle(tr("Bookmark All Tabs")); @@ -535,15 +573,17 @@ void BookmarksManager::insertAllTabs() size.setWidth(350); dialog->resize(size); dialog->exec(); - if (dialog->result() == QDialog::Rejected) + if (dialog->result() == QDialog::Rejected) { return; + } - foreach (WebTab* tab, getQupZilla()->tabWidget()->allTabs(false)) { + foreach(WebTab * tab, getQupZilla()->tabWidget()->allTabs(false)) { WebView* view = tab->view(); - if (view->url().isEmpty()) + if (view->url().isEmpty()) { continue; + } - m_bookmarksModel->saveBookmark(view->url(), view->title(), view->siteIcon(),BookmarksModel::fromTranslatedFolder(combo->currentText())); + m_bookmarksModel->saveBookmark(view->url(), view->title(), view->siteIcon(), BookmarksModel::fromTranslatedFolder(combo->currentText())); } delete dialog; @@ -552,8 +592,9 @@ void BookmarksManager::insertAllTabs() void BookmarksManager::optimizeDb() { BrowsingLibrary* b = qobject_cast(parentWidget()->parentWidget()); - if (!b) + if (!b) { return; + } b->optimizeDatabase(); } diff --git a/src/bookmarks/bookmarksmanager.h b/src/bookmarks/bookmarksmanager.h index fd700a3fe..7d8be17e7 100644 --- a/src/bookmarks/bookmarksmanager.h +++ b/src/bookmarks/bookmarksmanager.h @@ -26,8 +26,9 @@ #include "bookmarksmodel.h" -namespace Ui { - class BookmarksManager; +namespace Ui +{ +class BookmarksManager; } class WebView; diff --git a/src/bookmarks/bookmarksmodel.cpp b/src/bookmarks/bookmarksmodel.cpp index 282e13a20..cffe870eb 100644 --- a/src/bookmarks/bookmarksmodel.cpp +++ b/src/bookmarks/bookmarksmodel.cpp @@ -25,7 +25,7 @@ // However from bookmark icon, it is not possible to add more than one bookmark // Only from Ctrl+D dialog it is possible -BookmarksModel::BookmarksModel(QObject *parent) +BookmarksModel::BookmarksModel(QObject* parent) : QObject(parent) { loadSettings(); @@ -33,17 +33,17 @@ BookmarksModel::BookmarksModel(QObject *parent) void BookmarksModel::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); - m_showMostVisited = settings.value("showMostVisited",true).toBool(); + m_showMostVisited = settings.value("showMostVisited", true).toBool(); settings.endGroup(); } void BookmarksModel::setShowingMostVisited(bool state) { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); - settings.setValue("showMostVisited",state); + settings.setValue("showMostVisited", state); settings.endGroup(); m_showMostVisited = state; } @@ -55,7 +55,7 @@ bool BookmarksModel::isBookmarked(const QUrl &url) query.bindValue(0, url.toString()); query.exec(); query.next(); - return query.value(0).toInt()>0; + return query.value(0).toInt() > 0; } // Bookmark search priority: @@ -66,20 +66,23 @@ int BookmarksModel::bookmarkId(const QUrl &url) query.prepare("SELECT id FROM bookmarks WHERE url=? AND folder='bookmarksMenu' "); query.bindValue(0, url.toString()); query.exec(); - if (query.next()) + if (query.next()) { return query.value(0).toInt(); + } query.prepare("SELECT id FROM bookmarks WHERE url=? AND folder='bookmarksToolbar' "); query.bindValue(0, url.toString()); query.exec(); - if (query.next()) + if (query.next()) { return query.value(0).toInt(); + } query.prepare("SELECT id FROM bookmarks WHERE url=? "); query.bindValue(0, url.toString()); query.exec(); - if (query.next()) + if (query.next()) { return query.value(0).toInt(); + } return -1; } @@ -92,8 +95,9 @@ int BookmarksModel::bookmarkId(const QUrl &url, const QString &title, const QStr query.bindValue(1, title); query.bindValue(2, folder); query.exec(); - if (query.next()) + if (query.next()) { return query.value(0).toInt(); + } return -1; } @@ -117,8 +121,9 @@ BookmarksModel::Bookmark BookmarksModel::getBookmark(int id) bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder) { - if (url.isEmpty() || title.isEmpty() || folder.isEmpty()) + if (url.isEmpty() || title.isEmpty() || folder.isEmpty()) { return false; + } QSqlQuery query; query.prepare("INSERT INTO bookmarks (url, title, folder, icon) VALUES (?,?,?,?)"); @@ -127,8 +132,9 @@ bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const Q query.bindValue(2, folder); query.bindValue(3, IconProvider::iconToBase64(icon)); - if (!query.exec()) + if (!query.exec()) { return false; + } Bookmark bookmark; bookmark.id = query.lastInsertId().toInt(); @@ -143,7 +149,7 @@ bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const Q return true; } -bool BookmarksModel::saveBookmark(WebView *view, const QString &folder) +bool BookmarksModel::saveBookmark(WebView* view, const QString &folder) { return saveBookmark(view->url(), view->title(), view->siteIcon(), folder); } @@ -154,8 +160,9 @@ bool BookmarksModel::removeBookmark(int id) query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?"); query.bindValue(0, id); query.exec(); - if (!query.next()) + if (!query.next()) { return false; + } Bookmark bookmark; bookmark.id = id; @@ -165,8 +172,9 @@ bool BookmarksModel::removeBookmark(int id) bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); bookmark.inSubfolder = isSubfolder(bookmark.folder); - if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) + if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) { return false; + } emit bookmarkDeleted(bookmark); mApp->sendMessages(MainApplication::BookmarksChanged, true); @@ -205,11 +213,13 @@ bool BookmarksModel::removeBookmark(WebView* view) bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url, const QString &folder) { - if (title.isEmpty() && url.isEmpty() && folder.isEmpty()) + if (title.isEmpty() && url.isEmpty() && folder.isEmpty()) { return false; + } QSqlQuery query; - if (!query.exec("SELECT title, url, folder, icon FROM bookmarks WHERE id = "+QString::number(id))) + if (!query.exec("SELECT title, url, folder, icon FROM bookmarks WHERE id = " + QString::number(id))) { return false; + } query.next(); @@ -235,8 +245,9 @@ bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url, query.bindValue(2, after.folder); query.bindValue(3, id); - if (!query.exec()) + if (!query.exec()) { return false; + } emit bookmarkEdited(before, after); mApp->sendMessages(MainApplication::BookmarksChanged, true); @@ -249,13 +260,15 @@ bool BookmarksModel::createFolder(const QString &name) query.prepare("SELECT name FROM folders WHERE name = ?"); query.bindValue(0, name); query.exec(); - if (query.next()) + if (query.next()) { return false; + } query.prepare("INSERT INTO folders (name, subfolder) VALUES (?, 'no')"); query.bindValue(0, name); - if (!query.exec()) + if (!query.exec()) { return false; + } emit folderAdded(name); mApp->sendMessages(MainApplication::BookmarksChanged, true); @@ -264,26 +277,31 @@ bool BookmarksModel::createFolder(const QString &name) bool BookmarksModel::removeFolder(const QString &name) { - if (name == tr("Bookmarks In Menu") || name == tr("Bookmarks In ToolBar")) + if (name == tr("Bookmarks In Menu") || name == tr("Bookmarks In ToolBar")) { return false; + } QSqlQuery query; query.prepare("SELECT id FROM bookmarks WHERE folder = ? "); query.bindValue(0, name); - if (!query.exec()) + if (!query.exec()) { return false; - while (query.next()) + } + while (query.next()) { removeBookmark(query.value(0).toInt()); + } query.prepare("DELETE FROM folders WHERE name=?"); query.bindValue(0, name); - if (!query.exec()) + if (!query.exec()) { return false; + } query.prepare("DELETE FROM bookmarks WHERE folder=?"); query.bindValue(0, name); - if (!query.exec()) + if (!query.exec()) { return false; + } emit folderDeleted(name); mApp->sendMessages(MainApplication::BookmarksChanged, true); @@ -296,20 +314,23 @@ bool BookmarksModel::renameFolder(const QString &before, const QString &after) query.prepare("SELECT name FROM folders WHERE name = ?"); query.bindValue(0, after); query.exec(); - if (query.next()) + if (query.next()) { return false; + } query.prepare("UPDATE folders SET name=? WHERE name=?"); query.bindValue(0, after); query.bindValue(1, before); - if (!query.exec()) - return false; + if (!query.exec()) { + return false; + } query.prepare("UPDATE bookmarks SET folder=? WHERE folder=?"); query.bindValue(0, after); query.bindValue(1, before); - if (!query.exec()) - return false; + if (!query.exec()) { + return false; + } emit folderRenamed(before, after); return true; @@ -321,13 +342,15 @@ bool BookmarksModel::createSubfolder(const QString &name) query.prepare("SELECT name FROM folders WHERE name = ?"); query.bindValue(0, name); query.exec(); - if (query.next()) + if (query.next()) { return false; + } query.prepare("INSERT INTO folders (name, subfolder) VALUES (?, 'yes')"); query.bindValue(0, name); - if (!query.exec()) + if (!query.exec()) { return false; + } emit subfolderAdded(name); mApp->sendMessages(MainApplication::BookmarksChanged, true); @@ -340,49 +363,62 @@ bool BookmarksModel::isSubfolder(const QString &name) query.prepare("SELECT subfolder FROM folders WHERE name = ?"); query.bindValue(0, name); query.exec(); - if (!query.next()) + if (!query.next()) { return false; + } return query.value(0).toString() == "yes"; } bool BookmarksModel::bookmarksEqual(const Bookmark &one, const Bookmark &two) { - if (one.id != two.id) + if (one.id != two.id) { return false; - if (one.title != two.title) + } + if (one.title != two.title) { return false; - if (one.folder != two.folder) + } + if (one.folder != two.folder) { return false; - if (one.url != two.url) + } + if (one.url != two.url) { return false; + } return true; } QString BookmarksModel::toTranslatedFolder(const QString &name) { QString trFolder; - if (name == "bookmarksMenu") + if (name == "bookmarksMenu") { trFolder = tr("Bookmarks In Menu"); - else if (name == "bookmarksToolbar") + } + else if (name == "bookmarksToolbar") { trFolder = tr("Bookmarks In ToolBar"); - else if (name == "unsorted") + } + else if (name == "unsorted") { trFolder = tr("Unsorted Bookmarks"); - else + } + else { trFolder = name; + } return trFolder; } QString BookmarksModel::fromTranslatedFolder(const QString &name) { QString folder; - if (name == tr("Bookmarks In Menu")) + if (name == tr("Bookmarks In Menu")) { folder = "bookmarksMenu"; - else if (name == tr("Bookmarks In ToolBar")) + } + else if (name == tr("Bookmarks In ToolBar")) { folder = "bookmarksToolbar"; - else if (name == tr("Unsorted Bookmarks")) + } + else if (name == tr("Unsorted Bookmarks")) { folder = "unsorted"; - else + } + else { folder = name; + } return folder; } diff --git a/src/bookmarks/bookmarksmodel.h b/src/bookmarks/bookmarksmodel.h index ad804c0dd..9fd9385ce 100644 --- a/src/bookmarks/bookmarksmodel.h +++ b/src/bookmarks/bookmarksmodel.h @@ -39,13 +39,12 @@ public: QIcon icon; bool inSubfolder; - Bookmark() - { + Bookmark() { + id = -1; inSubfolder = false; } - bool operator==(const Bookmark &other) - { + bool operator==(const Bookmark &other) const { return (this->title == other.title && this->folder == other.folder && this->url == other.url && diff --git a/src/bookmarks/bookmarkstoolbar.cpp b/src/bookmarks/bookmarkstoolbar.cpp index 7b2196954..17b47f3b9 100644 --- a/src/bookmarks/bookmarkstoolbar.cpp +++ b/src/bookmarks/bookmarkstoolbar.cpp @@ -39,10 +39,10 @@ BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent) connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(addBookmark(BookmarksModel::Bookmark))); connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(removeBookmark(BookmarksModel::Bookmark))); - connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark))); + connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark))); connect(m_bookmarksModel, SIGNAL(subfolderAdded(QString)), this, SLOT(subfolderAdded(QString))); connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(folderDeleted(QString))); - connect(m_bookmarksModel, SIGNAL(folderRenamed(QString,QString)), this, SLOT(folderRenamed(QString,QString))); + connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(folderRenamed(QString, QString))); // QTimer::singleShot(0, this, SLOT(refreshBookmarks())); refreshBookmarks(); @@ -62,7 +62,7 @@ void BookmarksToolbar::customContextMenuRequested(const QPoint &pos) //Prevent choosing first option with double rightclick QPoint position = QCursor::pos(); - QPoint p(position.x(), position.y()+1); + QPoint p(position.x(), position.y() + 1); menu.exec(p); } @@ -71,10 +71,11 @@ void BookmarksToolbar::showBookmarkContextMenu(const QPoint &pos) Q_UNUSED(pos) ToolButton* button = qobject_cast(sender()); - if (!button) + if (!button) { return; + } - QVariant buttonPointer = qVariantFromValue((void *) button); + QVariant buttonPointer = qVariantFromValue((void*) button); QMenu menu; menu.addAction(IconProvider::fromTheme("go-next"), tr("Move right"), this, SLOT(moveRight()))->setData(buttonPointer); @@ -84,25 +85,28 @@ void BookmarksToolbar::showBookmarkContextMenu(const QPoint &pos) //Prevent choosing first option with double rightclick QPoint position = QCursor::pos(); - QPoint p(position.x(), position.y()+1); + QPoint p(position.x(), position.y() + 1); menu.exec(p); } void BookmarksToolbar::moveRight() { QAction* act = qobject_cast (sender()); - if (!act) + if (!act) { return; + } ToolButton* button = (ToolButton*) act->data().value(); int index = m_layout->indexOf(button); - if (index == m_layout->count() - 1) + if (index == m_layout->count() - 1) { return; + } ToolButton* buttonRight = qobject_cast (m_layout->itemAt(index + 1)->widget()); - if (!buttonRight || buttonRight->menu()) + if (!buttonRight || buttonRight->menu()) { return; + } Bookmark bookmark = button->data().value(); Bookmark bookmarkRight = buttonRight->data().value(); @@ -125,18 +129,21 @@ void BookmarksToolbar::moveRight() void BookmarksToolbar::moveLeft() { QAction* act = qobject_cast (sender()); - if (!act) + if (!act) { return; + } ToolButton* button = (ToolButton*) act->data().value(); int index = m_layout->indexOf(button); - if (index == 0) + if (index == 0) { return; + } ToolButton* buttonLeft = qobject_cast (m_layout->itemAt(index - 1)->widget()); - if (!buttonLeft) + if (!buttonLeft) { return; + } Bookmark bookmark = button->data().value(); Bookmark bookmarkLeft = buttonLeft->data().value(); @@ -159,12 +166,14 @@ void BookmarksToolbar::moveLeft() void BookmarksToolbar::removeButton() { QAction* act = qobject_cast (sender()); - if (!act) + if (!act) { return; + } ToolButton* button = (ToolButton*) act->data().value(); - if (!button) + if (!button) { return; + } Bookmark bookmark = button->data().value(); m_bookmarksModel->removeBookmark(bookmark.id); @@ -178,8 +187,9 @@ void BookmarksToolbar::hidePanel() void BookmarksToolbar::loadClickedBookmark() { ToolButton* button = qobject_cast(sender()); - if (!button) + if (!button) { return; + } Bookmark bookmark = button->data().value(); @@ -189,8 +199,9 @@ void BookmarksToolbar::loadClickedBookmark() void BookmarksToolbar::loadClickedBookmarkInNewTab() { ToolButton* button = qobject_cast(sender()); - if (!button) + if (!button) { return; + } Bookmark bookmark = button->data().value(); @@ -207,11 +218,13 @@ int BookmarksToolbar::indexOfLastBookmark() { for (int i = m_layout->count() - 1; i >= 0; i--) { ToolButton* button = qobject_cast(m_layout->itemAt(i)->widget()); - if (!button) + if (!button) { continue; + } - if (!button->menu()) + if (!button->menu()) { return i + 1; + } } return 0; @@ -238,8 +251,9 @@ void BookmarksToolbar::folderDeleted(const QString &name) for (int i = index; i < m_layout->count(); i++) { ToolButton* button = qobject_cast(m_layout->itemAt(i)->widget()); - if (!button) + if (!button) { continue; + } if (button->text() == name) { delete button; @@ -254,8 +268,9 @@ void BookmarksToolbar::folderRenamed(const QString &before, const QString &after for (int i = index; i < m_layout->count(); i++) { ToolButton* button = qobject_cast(m_layout->itemAt(i)->widget()); - if (!button) + if (!button) { continue; + } if (button->text() == before) { button->setText(after); @@ -267,12 +282,13 @@ void BookmarksToolbar::folderRenamed(const QString &before, const QString &after void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark) { - if (bookmark.folder != "bookmarksToolbar") + if (bookmark.folder != "bookmarksToolbar") { return; + } QString title = bookmark.title; - if (title.length()>15) { + if (title.length() > 15) { title.truncate(13); - title+=".."; + title += ".."; } QVariant v; @@ -306,8 +322,9 @@ void BookmarksToolbar::removeBookmark(const BookmarksModel::Bookmark &bookmark) { for (int i = 0; i < m_layout->count(); i++) { ToolButton* button = qobject_cast(m_layout->itemAt(i)->widget()); - if (!button) + if (!button) { continue; + } Bookmark book = button->data().value(); @@ -320,23 +337,26 @@ void BookmarksToolbar::removeBookmark(const BookmarksModel::Bookmark &bookmark) void BookmarksToolbar::bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after) { - if (before.folder == "bookmarksToolbar" && after.folder != "bookmarksToolbar") //Editing from toolbar folder to other folder -> Remove bookmark + if (before.folder == "bookmarksToolbar" && after.folder != "bookmarksToolbar") { //Editing from toolbar folder to other folder -> Remove bookmark removeBookmark(before); - else if (before.folder != "bookmarksToolbar" && after.folder == "bookmarksToolbar") //Editing from other folder to toolbar folder -> Add bookmark + } + else if (before.folder != "bookmarksToolbar" && after.folder == "bookmarksToolbar") { //Editing from other folder to toolbar folder -> Add bookmark addBookmark(after); - else { //Editing bookmark already in toolbar + } + else { //Editing bookmark already in toolbar for (int i = 0; i < m_layout->count(); i++) { ToolButton* button = qobject_cast(m_layout->itemAt(i)->widget()); - if (!button) + if (!button) { continue; + } Bookmark book = button->data().value(); if (book == before) { QString title = after.title; - if (title.length()>15) { + if (title.length() > 15) { title.truncate(13); - title+=".."; + title += ".."; } QVariant v; @@ -357,7 +377,7 @@ void BookmarksToolbar::refreshBookmarks() { QSqlQuery query; query.exec("SELECT id, title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar' ORDER BY toolbar_position"); - while(query.next()) { + while (query.next()) { Bookmark bookmark; bookmark.id = query.value(0).toInt(); bookmark.title = query.value(1).toString(); @@ -365,9 +385,9 @@ void BookmarksToolbar::refreshBookmarks() bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); bookmark.folder = "bookmarksToolbar"; QString title = bookmark.title; - if (title.length()>15) { + if (title.length() > 15) { title.truncate(13); - title+=".."; + title += ".."; } QVariant v; @@ -390,7 +410,7 @@ void BookmarksToolbar::refreshBookmarks() } query.exec("SELECT name FROM folders WHERE subfolder='yes'"); - while(query.next()) { + while (query.next()) { ToolButton* b = new ToolButton(this); b->setPopupMode(QToolButton::InstantPopup); b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); @@ -424,8 +444,9 @@ void BookmarksToolbar::refreshBookmarks() void BookmarksToolbar::aboutToShowFolderMenu() { QMenu* menu = qobject_cast (sender()); - if (!menu) + if (!menu) { return; + } menu->clear(); QString folder = menu->title(); @@ -434,7 +455,7 @@ void BookmarksToolbar::aboutToShowFolderMenu() query.prepare("SELECT title, url, icon FROM bookmarks WHERE folder=?"); query.addBindValue(folder); query.exec(); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray()); @@ -445,8 +466,9 @@ void BookmarksToolbar::aboutToShowFolderMenu() menu->addAction(icon, title, p_QupZilla, SLOT(loadActionUrl()))->setData(url); } - if (menu->isEmpty()) + if (menu->isEmpty()) { menu->addAction(tr("Empty")); + } } void BookmarksToolbar::refreshMostVisited() @@ -454,14 +476,15 @@ void BookmarksToolbar::refreshMostVisited() m_menuMostVisited->clear(); QList mostList = m_historyModel->mostVisited(10); - foreach (HistoryModel::HistoryEntry entry, mostList) { - if (entry.title.length()>40) { + foreach(HistoryModel::HistoryEntry entry, mostList) { + if (entry.title.length() > 40) { entry.title.truncate(40); - entry.title+=".."; + entry.title += ".."; } m_menuMostVisited->addAction(_iconForUrl(entry.url), entry.title, p_QupZilla, SLOT(loadActionUrl()))->setData(entry.url); } - if (m_menuMostVisited->isEmpty()) + if (m_menuMostVisited->isEmpty()) { m_menuMostVisited->addAction(tr("Empty")); + } } diff --git a/src/bookmarks/bookmarkswidget.cpp b/src/bookmarks/bookmarkswidget.cpp index ce501585c..0fead22ff 100644 --- a/src/bookmarks/bookmarkswidget.cpp +++ b/src/bookmarks/bookmarkswidget.cpp @@ -22,9 +22,9 @@ BookmarksWidget::BookmarksWidget(int bookmarkId, QWidget* parent) : QMenu(parent) - ,ui(new Ui::BookmarksWidget) - ,m_bookmarkId(bookmarkId) - ,m_bookmarksModel(0) + , ui(new Ui::BookmarksWidget) + , m_bookmarkId(bookmarkId) + , m_bookmarksModel(0) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); @@ -39,7 +39,7 @@ BookmarksWidget::BookmarksWidget(int bookmarkId, QWidget* parent) : void BookmarksWidget::loadBookmark() { BookmarksModel::Bookmark bookmark = m_bookmarksModel->getBookmark(m_bookmarkId); - ui->name->setText( bookmark.title ); + ui->name->setText(bookmark.title); // Bookmark folders ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"), "unsorted"); @@ -47,10 +47,11 @@ void BookmarksWidget::loadBookmark() ui->folder->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"), "bookmarksToolbar"); QSqlQuery query; query.exec("SELECT name FROM folders"); - while(query.next()) + while (query.next()) { ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString()); + } - ui->folder->setCurrentIndex( ui->folder->findData(bookmark.folder) ); + ui->folder->setCurrentIndex(ui->folder->findData(bookmark.folder)); ui->name->setCursorPosition(0); } @@ -63,14 +64,14 @@ void BookmarksWidget::removeBookmark() void BookmarksWidget::saveBookmark() { - m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString() ); + m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString()); close(); } void BookmarksWidget::showAt(QWidget* _parent) { QPoint p = _parent->mapToGlobal(QPoint(0, 0)); - move( (p.x()+_parent->width() ) - width(), p.y() + _parent->height()); + move((p.x() + _parent->width()) - width(), p.y() + _parent->height()); show(); } diff --git a/src/bookmarks/bookmarkswidget.h b/src/bookmarks/bookmarkswidget.h index 986a04bcd..a012d9826 100644 --- a/src/bookmarks/bookmarkswidget.h +++ b/src/bookmarks/bookmarkswidget.h @@ -29,8 +29,9 @@ #include #include -namespace Ui { - class BookmarksWidget; +namespace Ui +{ +class BookmarksWidget; } class BookmarksModel; diff --git a/src/bookmarksimport/bookmarksimportdialog.cpp b/src/bookmarksimport/bookmarksimportdialog.cpp index ae72dd438..da7679057 100644 --- a/src/bookmarksimport/bookmarksimportdialog.cpp +++ b/src/bookmarksimport/bookmarksimportdialog.cpp @@ -44,10 +44,11 @@ void BookmarksImportDialog::nextPage() { switch (m_currentPage) { case 0: - if (!ui->browserList->currentItem()) + if (!ui->browserList->currentItem()) { return; + } - m_browser = (Browser) (ui->browserList->currentRow()); + m_browser = (Browser)(ui->browserList->currentRow()); setupBrowser(m_browser); ui->iconLabel->setPixmap(m_browserPixmap); ui->importingFromLabel->setText(tr("Importing from %1").arg(m_browserName)); @@ -61,8 +62,9 @@ void BookmarksImportDialog::nextPage() break; case 1: - if (ui->fileLine->text().isEmpty()) + if (ui->fileLine->text().isEmpty()) { return; + } if (exportedOK()) { m_currentPage++; @@ -89,7 +91,7 @@ void BookmarksImportDialog::startFetchingIcons() ui->progressBar->setMaximum(m_exportedBookmarks.count()); int i = 0; - foreach (BookmarksModel::Bookmark b, m_exportedBookmarks) { + foreach(BookmarksModel::Bookmark b, m_exportedBookmarks) { QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, b.title); item->setIcon(0, QWebSettings::globalSettings()->webGraphic(QWebSettings::DefaultFrameIconGraphic)); @@ -132,8 +134,9 @@ void BookmarksImportDialog::loadFinished() void BookmarksImportDialog::iconFetched(const QIcon &icon) { IconFetcher* fetcher = qobject_cast(sender()); - if (!fetcher) + if (!fetcher) { return; + } QUrl url; for (int i = 0; i < m_fetchers.count(); i++) { @@ -144,17 +147,19 @@ void BookmarksImportDialog::iconFetched(const QIcon &icon) } } - if (url.isEmpty()) + if (url.isEmpty()) { return; + } QList items = ui->treeWidget->findItems(url.toString(), Qt::MatchExactly, 1); - if (items.count() == 0) + if (items.count() == 0) { return; + } - foreach (QTreeWidgetItem* item, items) { + foreach(QTreeWidgetItem * item, items) { item->setIcon(0, icon); - foreach (BookmarksModel::Bookmark b, m_exportedBookmarks) { + foreach(BookmarksModel::Bookmark b, m_exportedBookmarks) { if (b.url == url) { m_exportedBookmarks.removeOne(b); b.icon = icon; @@ -170,30 +175,35 @@ bool BookmarksImportDialog::exportedOK() if (m_browser == Firefox) { FirefoxImporter firefox(this); firefox.setFile(ui->fileLine->text()); - if (firefox.openDatabase()) + if (firefox.openDatabase()) { m_exportedBookmarks = firefox.exportBookmarks(); + } if (firefox.error()) { QMessageBox::critical(this, tr("Error!"), firefox.errorString()); return false; } return true; - } else if (m_browser == Chrome) { + } + else if (m_browser == Chrome) { ChromeImporter chrome(this); chrome.setFile(ui->fileLine->text()); - if (chrome.openFile()) + if (chrome.openFile()) { m_exportedBookmarks = chrome.exportBookmarks(); + } if (chrome.error()) { QMessageBox::critical(this, tr("Error!"), chrome.errorString()); return false; } return true; - } else if (m_browser == Opera) { + } + else if (m_browser == Opera) { OperaImporter opera(this); opera.setFile(ui->fileLine->text()); - if (opera.openFile()) + if (opera.openFile()) { m_exportedBookmarks = opera.exportBookmarks(); + } if (opera.error()) { QMessageBox::critical(this, tr("Error!"), opera.errorString()); @@ -210,14 +220,17 @@ void BookmarksImportDialog::setFile() #ifdef Q_WS_WIN if (m_browser == IE) { QString path = QFileDialog::getExistingDirectory(this, tr("Choose directory...")); - if (!path.isEmpty()) + if (!path.isEmpty()) { ui->fileLine->setText(path); - } else + } + } + else #endif { QString path = QFileDialog::getOpenFileName(this, tr("Choose file..."), QDir::homePath(), m_browserBookmarkFile); - if (!path.isEmpty()) + if (!path.isEmpty()) { ui->fileLine->setText(path); + } } ui->nextButton->setEnabled(!ui->fileLine->text().isEmpty()); @@ -229,11 +242,12 @@ void BookmarksImportDialog::addExportedBookmarks() BookmarksModel* model = mApp->bookmarksModel(); - if (m_exportedBookmarks.count() > 0) - model->createFolder(m_exportedBookmarks.at(0).folder); + if (m_exportedBookmarks.count() > 0) { + model->createFolder(m_exportedBookmarks.at(0).folder); + } - foreach (BookmarksModel::Bookmark b, m_exportedBookmarks) - model->saveBookmark(b.url, b.title, b.icon, b.folder); + foreach(BookmarksModel::Bookmark b, m_exportedBookmarks) + model->saveBookmark(b.url, b.title, b.icon, b.folder); qApp->restoreOverrideCursor(); } @@ -250,9 +264,9 @@ void BookmarksImportDialog::setupBrowser(Browser browser) m_browserFileText2 = tr("Please choose this file to begin importing bookmarks."); m_standardDir = #ifdef Q_WS_WIN - "%APPDATA%/Mozilla/"; + "%APPDATA%/Mozilla/"; #else - "/home/user/.mozilla/firefox/profilename/"; + "/home/user/.mozilla/firefox/profilename/"; #endif break; @@ -281,9 +295,9 @@ void BookmarksImportDialog::setupBrowser(Browser browser) m_browserFileText2 = tr("Please choose this file to begin importing bookmarks."); m_standardDir = #ifdef Q_WS_WIN - "%APPDATA%/Chrome/Default/"; + "%APPDATA%/Chrome/Default/"; #else - "/home/user/.opera/"; + "/home/user/.opera/"; #endif break; @@ -304,7 +318,8 @@ void BookmarksImportDialog::setupBrowser(Browser browser) BookmarksImportDialog::~BookmarksImportDialog() { if (m_fetchers.count() > 0) { - for (int i = 0; i < m_fetchers.count(); i++) {tr(""); + for (int i = 0; i < m_fetchers.count(); i++) { + tr(""); IconFetcher* fetcher = m_fetchers.at(i).first; delete fetcher; } diff --git a/src/bookmarksimport/bookmarksimportdialog.h b/src/bookmarksimport/bookmarksimportdialog.h index 586d83b60..e46943785 100644 --- a/src/bookmarksimport/bookmarksimportdialog.h +++ b/src/bookmarksimport/bookmarksimportdialog.h @@ -28,8 +28,9 @@ #include "bookmarksmodel.h" -namespace Ui { - class BookmarksImportDialog; +namespace Ui +{ +class BookmarksImportDialog; } class IconFetcher; @@ -57,7 +58,7 @@ private: void startFetchingIcons(); void addExportedBookmarks(); - Ui::BookmarksImportDialog *ui; + Ui::BookmarksImportDialog* ui; int m_currentPage; Browser m_browser; diff --git a/src/bookmarksimport/chromeimporter.cpp b/src/bookmarksimport/chromeimporter.cpp index 0449e6470..e3c322480 100644 --- a/src/bookmarksimport/chromeimporter.cpp +++ b/src/bookmarksimport/chromeimporter.cpp @@ -61,15 +61,16 @@ QList ChromeImporter::exportBookmarks() } QScriptEngine* scriptEngine = new QScriptEngine(); - foreach (QString parsedString, parsedBookmarks) { + foreach(QString parsedString, parsedBookmarks) { parsedString = "(" + parsedString + ")"; if (scriptEngine->canEvaluate(parsedString)) { QScriptValue object = scriptEngine->evaluate(parsedString); QString name = object.property("name").toString(); QString url = object.property("url").toString(); - if (name.isEmpty() || url.isEmpty()) + if (name.isEmpty() || url.isEmpty()) { continue; + } BookmarksModel::Bookmark b; b.folder = "Chrome Import"; @@ -77,7 +78,8 @@ QList ChromeImporter::exportBookmarks() b.url = url; list.append(b); - } else { + } + else { m_error = true; m_errorString = tr("Cannot evaluate JSON code."); } diff --git a/src/bookmarksimport/firefoximporter.cpp b/src/bookmarksimport/firefoximporter.cpp index f544a7175..73cceb4e2 100644 --- a/src/bookmarksimport/firefoximporter.cpp +++ b/src/bookmarksimport/firefoximporter.cpp @@ -17,7 +17,7 @@ * ============================================================ */ #include "firefoximporter.h" -FirefoxImporter::FirefoxImporter(QObject *parent) +FirefoxImporter::FirefoxImporter(QObject* parent) : QObject(parent) , m_error(false) , m_errorString(tr("No Error")) @@ -56,20 +56,22 @@ QList FirefoxImporter::exportBookmarks() QSqlQuery query(db); query.exec("SELECT title, fk FROM moz_bookmarks WHERE title != ''"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); int placesId = query.value(1).toInt(); QSqlQuery query2(db); query2.exec("SELECT url FROM moz_places WHERE id=" + QString::number(placesId)); - if (!query2.next()) - continue; + if (!query2.next()) { + continue; + } QString url = query2.value(0).toString(); - if (title.isEmpty() || url.isEmpty() || url.startsWith("place:")) + if (title.isEmpty() || url.isEmpty() || url.startsWith("place:")) { continue; + } BookmarksModel::Bookmark b; b.folder = "Firefox Import"; diff --git a/src/bookmarksimport/operaimporter.cpp b/src/bookmarksimport/operaimporter.cpp index 4b87a0ed4..431ad9123 100644 --- a/src/bookmarksimport/operaimporter.cpp +++ b/src/bookmarksimport/operaimporter.cpp @@ -66,8 +66,9 @@ QList OperaImporter::exportBookmarks() rx2.indexIn(string); QString url = rx2.cap(1); - if (name.isEmpty() || url.isEmpty()) + if (name.isEmpty() || url.isEmpty()) { continue; + } BookmarksModel::Bookmark b; b.folder = "Opera Import"; diff --git a/src/cookies/cookiejar.cpp b/src/cookies/cookiejar.cpp index 68ae35ef5..e8e0ceac5 100644 --- a/src/cookies/cookiejar.cpp +++ b/src/cookies/cookiejar.cpp @@ -45,12 +45,13 @@ void CookieJar::setAllowCookies(bool allow) bool CookieJar::setCookiesFromUrl(const QList &cookieList, const QUrl &url) { - if (!m_allowCookies) + if (!m_allowCookies) { return QNetworkCookieJar::setCookiesFromUrl(QList(), url); + } QList newList = cookieList; - foreach (QNetworkCookie cok, newList) { + foreach(QNetworkCookie cok, newList) { if (m_allowCookiesFromDomain && !QString("." + url.host()).contains(cok.domain().remove("www."))) { #ifdef COOKIE_DEBUG qDebug() << "purged for domain mismatch" << cok; @@ -72,17 +73,18 @@ bool CookieJar::setCookiesFromUrl(const QList &cookieList, const void CookieJar::saveCookies() { - if (m_deleteOnClose) + if (m_deleteOnClose) { return; + } QList allCookies = getAllCookies(); - QFile file(m_activeProfil+"cookies.dat"); + QFile file(m_activeProfil + "cookies.dat"); file.open(QIODevice::WriteOnly); QDataStream stream(&file); int count = allCookies.count(); stream << count; - for (int i = 0; i restoredCookies; - QFile file(m_activeProfil+"cookies.dat"); + QFile file(m_activeProfil + "cookies.dat"); file.open(QIODevice::ReadOnly); QDataStream stream(&file); int count; stream >> count; - for (int i = 0; i> rawForm; QNetworkCookie cok = QNetworkCookie::parseCookies(rawForm).at(0); - if (cok.expirationDate() < now) + if (cok.expirationDate() < now) { continue; - if (cok.isSessionCookie()) + } + if (cok.isSessionCookie()) { continue; + } restoredCookies.append(cok); } @@ -132,7 +137,8 @@ void CookieJar::turnPrivateJar(bool state) if (state) { m_tempList = QNetworkCookieJar::allCookies(); QNetworkCookieJar::setAllCookies(QList()); - } else { + } + else { QNetworkCookieJar::setAllCookies(m_tempList); m_tempList.clear(); } diff --git a/src/cookies/cookiemanager.cpp b/src/cookies/cookiemanager.cpp index d87894ad2..84671a2a2 100644 --- a/src/cookies/cookiemanager.cpp +++ b/src/cookies/cookiemanager.cpp @@ -33,7 +33,7 @@ CookieManager::CookieManager(QWidget* parent) ui->setupUi(this); qz_centerWidgetOnScreen(this); - connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + connect(ui->cookieTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); connect(ui->removeAll, SIGNAL(clicked()), this, SLOT(removeAll())); connect(ui->removeOne, SIGNAL(clicked()), this, SLOT(removeCookie())); connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(hide())); @@ -50,9 +50,10 @@ CookieManager::CookieManager(QWidget* parent) void CookieManager::removeAll() { QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"), - tr("Are you sure to delete all cookies on your computer?"), QMessageBox::Yes | QMessageBox::No); - if (button != QMessageBox::Yes) + tr("Are you sure to delete all cookies on your computer?"), QMessageBox::Yes | QMessageBox::No); + if (button != QMessageBox::Yes) { return; + } m_cookies.clear(); mApp->cookieJar()->setAllCookies(m_cookies); @@ -62,16 +63,18 @@ void CookieManager::removeAll() void CookieManager::removeCookie() { QTreeWidgetItem* current = ui->cookieTree->currentItem(); - if (!current) + if (!current) { return; + } int indexToNavigate = -1; if (current->text(1).isEmpty()) { //Remove whole cookie group QString domain = current->whatsThis(0); foreach(QNetworkCookie cok, m_cookies) { - if (cok.domain() == domain || cok.domain() == domain.mid(1)) + if (cok.domain() == domain || cok.domain() == domain.mid(1)) { m_cookies.removeOne(cok); + } } indexToNavigate = ui->cookieTree->indexOfTopLevelItem(current) - 1; @@ -91,15 +94,17 @@ void CookieManager::removeCookie() ui->cookieTree->scrollToItem(scrollItem); } - if (!ui->search->text().isEmpty()) + if (!ui->search->text().isEmpty()) { search(); + } } void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* parent) { Q_UNUSED(parent); - if (!current) + if (!current) { return; + } if (current->text(1).isEmpty()) { ui->name->setText(tr("")); @@ -133,25 +138,28 @@ void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem void CookieManager::refreshTable(bool refreshCookieJar) { - if (refreshCookieJar) + if (refreshCookieJar) { m_cookies = mApp->cookieJar()->getAllCookies(); + } ui->cookieTree->setUpdatesEnabled(false); ui->cookieTree->clear(); QString cookServer; - for (int i = 0; i findParent = ui->cookieTree->findItems(cookServer, 0); if (findParent.count() == 1) { item = new QTreeWidgetItem(findParent.at(0)); - }else{ + } + else { QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->cookieTree); newParent->setText(0, cookServer); newParent->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); @@ -160,7 +168,7 @@ void CookieManager::refreshTable(bool refreshCookieJar) item = new QTreeWidgetItem(newParent); } - item->setText(0,"."+cookServer); + item->setText(0, "." + cookServer); item->setText(1, cok.name()); item->setWhatsThis(1, QString::number(i)); ui->cookieTree->addTopLevelItem(item); diff --git a/src/cookies/cookiemanager.h b/src/cookies/cookiemanager.h index bd35c0ac0..f56477eaf 100644 --- a/src/cookies/cookiemanager.h +++ b/src/cookies/cookiemanager.h @@ -23,8 +23,9 @@ #include #include -namespace Ui { - class CookieManager; +namespace Ui +{ +class CookieManager; } class QupZilla; diff --git a/src/desktopnotifications/desktopnotification.cpp b/src/desktopnotifications/desktopnotification.cpp index ff1816db5..0a095793b 100644 --- a/src/desktopnotifications/desktopnotification.cpp +++ b/src/desktopnotifications/desktopnotification.cpp @@ -19,27 +19,28 @@ #include "ui_desktopnotification.h" DesktopNotification::DesktopNotification(bool setPosition) - : QWidget(0) - , ui(new Ui::DesktopNotification) - , m_settingPosition(setPosition) - , m_timeout(6000) - , m_timer(new QTimer(this)) + : QWidget(0) + , ui(new Ui::DesktopNotification) + , m_settingPosition(setPosition) + , m_timeout(6000) + , m_timer(new QTimer(this)) { ui->setupUi(this); setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint; - #ifdef Q_WS_WIN +#ifdef Q_WS_WIN flags |= Qt::ToolTip; - #endif +#endif setWindowFlags(flags); setWindowOpacity(0.9); m_timer->setSingleShot(true); connect(m_timer, SIGNAL(timeout()), this, SLOT(close())); - if (m_settingPosition) + if (m_settingPosition) { setCursor(Qt::OpenHandCursor); + } } void DesktopNotification::show() @@ -59,17 +60,19 @@ void DesktopNotification::show() void DesktopNotification::enterEvent(QEvent*) { - if (!m_settingPosition) + if (!m_settingPosition) { setWindowOpacity(0.5); + } } void DesktopNotification::leaveEvent(QEvent*) { - if (!m_settingPosition) + if (!m_settingPosition) { setWindowOpacity(0.9); + } } -void DesktopNotification::mousePressEvent(QMouseEvent *e) +void DesktopNotification::mousePressEvent(QMouseEvent* e) { if (!m_settingPosition) { close(); @@ -82,7 +85,7 @@ void DesktopNotification::mousePressEvent(QMouseEvent *e) } } -void DesktopNotification::mouseMoveEvent(QMouseEvent *e) +void DesktopNotification::mouseMoveEvent(QMouseEvent* e) { if (e->buttons() & Qt::LeftButton) { move(e->globalPos() - m_dragPosition); diff --git a/src/desktopnotifications/desktopnotification.h b/src/desktopnotifications/desktopnotification.h index 9ffd57b16..3a4cfec4f 100644 --- a/src/desktopnotifications/desktopnotification.h +++ b/src/desktopnotifications/desktopnotification.h @@ -22,8 +22,9 @@ #include #include -namespace Ui { - class DesktopNotification; +namespace Ui +{ +class DesktopNotification; } class DesktopNotification : public QWidget diff --git a/src/desktopnotifications/desktopnotificationsfactory.cpp b/src/desktopnotifications/desktopnotificationsfactory.cpp index 2e46bc2e3..be7024fad 100644 --- a/src/desktopnotifications/desktopnotificationsfactory.cpp +++ b/src/desktopnotifications/desktopnotificationsfactory.cpp @@ -28,7 +28,7 @@ DesktopNotificationsFactory::DesktopNotificationsFactory(QObject* parent) void DesktopNotificationsFactory::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Notifications"); m_enabled = settings.value("Enabled", true).toBool(); m_timeout = settings.value("Timeout", 6000).toInt(); @@ -43,13 +43,15 @@ void DesktopNotificationsFactory::loadSettings() void DesktopNotificationsFactory::notify(const QPixmap &icon, const QString &heading, const QString &text) { - if (!m_enabled) + if (!m_enabled) { return; + } switch (m_notifType) { case PopupWidget: - if (!m_desktopNotif) + if (!m_desktopNotif) { m_desktopNotif = new DesktopNotification(); + } m_desktopNotif->setPixmap(icon); m_desktopNotif->setHeading(heading); m_desktopNotif->setText(text); @@ -75,8 +77,9 @@ void DesktopNotificationsFactory::notify(const QPixmap &icon, const QString &hea args.append(m_timeout); QDBusMessage message = dbus.callWithArgumentList(QDBus::Block, "Notify", args); QVariantList list = message.arguments(); - if (list.count() > 0) + if (list.count() > 0) { m_uint = list.at(0).toInt(); + } #endif break; } diff --git a/src/downloads/downloadfilehelper.cpp b/src/downloads/downloadfilehelper.cpp index 0eb139464..8182b5027 100644 --- a/src/downloads/downloadfilehelper.cpp +++ b/src/downloads/downloadfilehelper.cpp @@ -30,8 +30,10 @@ DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QS , m_lastDownloadPath(lastDownloadPath) , m_downloadPath(downloadPath) , m_useNativeDialog(useNativeDialog) + , m_timer(0) , m_reply(0) , m_openFileChoosed(false) + , m_listWidget(0) , m_iconProvider(new QFileIconProvider) , m_manager(0) { @@ -55,7 +57,7 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask QTemporaryFile tempFile("XXXXXX." + info.suffix()); tempFile.open(); QFileInfo tempInfo(tempFile.fileName()); - m_fileIcon = m_iconProvider->icon(tempInfo).pixmap(30,30); + m_fileIcon = m_iconProvider->icon(tempInfo).pixmap(30, 30); QString mimeType = m_iconProvider->type(tempInfo); //Get Download Page and Close Empty Tab @@ -63,20 +65,25 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); WebPage* webPage = (WebPage*)(v.value()); if (webPage) { - if (!webPage->mainFrame()->url().isEmpty()) + if (!webPage->mainFrame()->url().isEmpty()) { m_downloadPage = webPage->mainFrame()->url(); - else if (webPage->history()->canGoBack()) + } + else if (webPage->history()->canGoBack()) { m_downloadPage = webPage->history()->backItem().url(); - else if (webPage->history()->count() == 0) + } + else if (webPage->history()->count() == 0) { webPage->getView()->closeTab(); + } } if (askWhatToDo) { DownloadOptionsDialog* dialog = new DownloadOptionsDialog(m_h_fileName, m_fileIcon, mimeType, reply->url(), mApp->activeWindow()); dialog->show(); connect(dialog, SIGNAL(dialogFinished(int)), this, SLOT(optionsDialogAccepted(int))); - } else + } + else { optionsDialogAccepted(2); + } } void DownloadFileHelper::optionsDialogAccepted(int finish) @@ -84,8 +91,9 @@ void DownloadFileHelper::optionsDialogAccepted(int finish) m_openFileChoosed = false; switch (finish) { case 0: //Cancelled - if (m_timer) + if (m_timer) { delete m_timer; + } return; break; case 1: //Open @@ -99,7 +107,8 @@ void DownloadFileHelper::optionsDialogAccepted(int finish) if (m_downloadPath.isEmpty()) { if (m_useNativeDialog) { fileNameChoosed(QFileDialog::getSaveFileName(mApp->getWindow(), tr("Save file as..."), m_lastDownloadPath + m_h_fileName)); - } else { + } + else { QFileDialog* dialog = new QFileDialog(mApp->getWindow()); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setWindowTitle(tr("Save file as...")); @@ -109,10 +118,13 @@ void DownloadFileHelper::optionsDialogAccepted(int finish) connect(dialog, SIGNAL(fileSelected(QString)), this, SLOT(fileNameChoosed(QString))); } } - else + else { fileNameChoosed(m_downloadPath + m_h_fileName, true); - } else + } + } + else { fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName, true); + } } void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoGenerated) @@ -121,8 +133,9 @@ void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoG if (m_userFileName.isEmpty()) { m_reply->abort(); - if (m_timer) + if (m_timer) { delete m_timer; + } return; } @@ -130,8 +143,8 @@ void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoG int pos = m_userFileName.lastIndexOf("/"); if (pos != -1) { int size = m_userFileName.size(); - m_path = m_userFileName.left(pos+1); - m_fileName = m_userFileName.right(size-pos-1); + m_path = m_userFileName.left(pos + 1); + m_fileName = m_userFileName.right(size - pos - 1); } if (fileNameAutoGenerated && QFile::exists(m_userFileName)) { @@ -142,17 +155,19 @@ void DownloadFileHelper::fileNameChoosed(const QString &name, bool fileNameAutoG int index = _tmpFileName.lastIndexOf("."); if (index == -1) { - _tmpFileName.append("("+QString::number(i)+")"); - } else { - _tmpFileName = _tmpFileName.mid(0, index) + "("+QString::number(i)+")" + _tmpFileName.mid(index); + _tmpFileName.append("(" + QString::number(i) + ")"); + } + else { + _tmpFileName = _tmpFileName.mid(0, index) + "(" + QString::number(i) + ")" + _tmpFileName.mid(index); } i++; } m_fileName = _tmpFileName; } - if (!m_path.contains(QDir::tempPath())) + if (!m_path.contains(QDir::tempPath())) { m_lastDownloadPath = m_path; + } QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("DownloadManager"); @@ -176,15 +191,17 @@ QString DownloadFileHelper::getFileName(QNetworkReply* reply) if (reply->hasRawHeader("Content-Disposition")) { QString value = reply->rawHeader("Content-Disposition"); int pos = value.indexOf("filename="); - if (pos!=-1) { + if (pos != -1) { QString name = value.mid(pos + 9); - if (name.startsWith('"') && name.endsWith('"')) + if (name.startsWith('"') && name.endsWith('"')) { name = name.mid(1, name.size() - 2); + } path = name; - } - } - if (path.isEmpty()) + } + } + if (path.isEmpty()) { path = reply->url().path(); + } QFileInfo info(path); QString baseName = info.completeBaseName(); @@ -194,14 +211,17 @@ QString DownloadFileHelper::getFileName(QNetworkReply* reply) baseName = tr("NoNameDownload"); } - if (!endName.isEmpty()) - endName="."+endName; + if (!endName.isEmpty()) { + endName = "." + endName; + } - QString name = baseName+endName; - if (name.startsWith("\"")) + QString name = baseName + endName; + if (name.startsWith("\"")) { name = name.mid(1); - if (name.endsWith("\";")) + } + if (name.endsWith("\";")) { name.remove("\";"); + } return name; } diff --git a/src/downloads/downloaditem.cpp b/src/downloads/downloaditem.cpp index b520735d3..93ebaa85c 100644 --- a/src/downloads/downloaditem.cpp +++ b/src/downloads/downloaditem.cpp @@ -44,15 +44,16 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QS qDebug() << __FUNCTION__ << item << reply << path << fileName; #endif QString fullPath = path + fileName; - if (QFile::exists(fullPath)) + if (QFile::exists(fullPath)) { QFile::remove(fullPath); + } m_outputFile.setFileName(fullPath); ui->setupUi(this); setMaximumWidth(525); - ui->button->setPixmap(IconProvider::standardIcon(QStyle::SP_BrowserStop).pixmap(20,20)); + ui->button->setPixmap(IconProvider::standardIcon(QStyle::SP_BrowserStop).pixmap(20, 20)); ui->fileName->setText(m_fileName); ui->downloadInfo->setText(tr("Remaining time unavailable")); ui->fileIcon->setPixmap(fileIcon); @@ -82,8 +83,9 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, const QS void DownloadItem::parentResized(const QSize &size) { - if (size.width() < 200) + if (size.width() < 200) { return; + } setMaximumWidth(size.width()); } @@ -93,8 +95,9 @@ void DownloadItem::metaDataChanged() // << download this picture emits metaDataChanged signal, but image is downloaded correctly QVariant locationHeader = m_reply->header(QNetworkRequest::LocationHeader); - if (!locationHeader.toUrl().isEmpty()) + if (!locationHeader.toUrl().isEmpty()) { qWarning("DownloadManager: metaDataChanged << URL: %s", qPrintable(locationHeader.toString())); + } // QMessageBox::information(m_item->listWidget()->parentWidget(), "Meta Data Changed", QString("Meta data changed feature unimplemented yet, sorry.\n URL: '%̈́'").arg(locationHeader.toUrl().toString())); } @@ -118,8 +121,9 @@ void DownloadItem::finished() #endif m_downloading = false; - if (m_openAfterFinish) + if (m_openAfterFinish) { openFile(); + } emit downloadFinished(true); } @@ -146,8 +150,10 @@ void DownloadItem::timerEvent(QTimerEvent* event) { if (event->timerId() == m_timer.timerId()) { updateDownloadInfo(m_currSpeed, m_received, m_total); - } else + } + else { QWidget::timerEvent(event); + } } int DownloadItem::progress() @@ -162,49 +168,59 @@ bool DownloadItem::isCancelled() QString DownloadItem::remaingTimeToString(QTime time) { - if (timedownloadInfo->setText(tr("%2 - unknown size (%3)").arg(currSize, speed)); - else + } + else { ui->downloadInfo->setText(tr("Remaining %1 - %2 of %3 (%4)").arg(remTime, currSize, fileSize, speed)); + } } void DownloadItem::stop(bool askForDeleteFile) @@ -240,8 +258,9 @@ void DownloadItem::stop(bool askForDeleteFile) qDebug() << __FUNCTION__; #endif - if (m_downloadStopped) + if (m_downloadStopped) { return; + } m_downloadStopped = true; m_openAfterFinish = false; @@ -264,8 +283,9 @@ void DownloadItem::stop(bool askForDeleteFile) if (askForDeleteFile) { QMessageBox::StandardButton button = QMessageBox::question(m_item->listWidget()->parentWidget(), tr("Delete file"), tr("Do you want to also delete dowloaded file?"), QMessageBox::Yes | QMessageBox::No); - if (button == QMessageBox::Yes) + if (button == QMessageBox::Yes) { QFile::remove(outputfile); + } } } @@ -288,8 +308,9 @@ void DownloadItem::customContextMenuRequested(const QPoint &pos) menu.addAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("Cancel downloading"), this, SLOT(stop()))->setEnabled(m_downloading); menu.addAction(QIcon::fromTheme("list-remove"), tr("Clear"), this, SLOT(clear()))->setEnabled(!m_downloading); - if (m_downloading || ui->downloadInfo->text().startsWith(tr("Cancelled")) || ui->downloadInfo->text().startsWith(tr("Error"))) + if (m_downloading || ui->downloadInfo->text().startsWith(tr("Cancelled")) || ui->downloadInfo->text().startsWith(tr("Error"))) { menu.actions().at(0)->setEnabled(false); + } menu.exec(mapToGlobal(pos)); } @@ -310,13 +331,16 @@ void DownloadItem::clear() void DownloadItem::openFile() { - if (m_downloading) + if (m_downloading) { return; - QFileInfo info(m_path+m_fileName); - if (info.exists()) + } + QFileInfo info(m_path + m_fileName); + if (info.exists()) { QDesktopServices::openUrl(QUrl::fromLocalFile(info.absoluteFilePath())); - else + } + else { QMessageBox::warning(m_item->listWidget()->parentWidget(), tr("Not found"), tr("Sorry, the file \n %1 \n was not found!").arg(info.absoluteFilePath())); + } } void DownloadItem::openFolder() @@ -342,8 +366,9 @@ void DownloadItem::error(QNetworkReply::NetworkError error) #ifdef DOWNMANAGER_DEBUG qDebug() << __FUNCTION__ << error; #endif - if (error != QNetworkReply::NoError) + if (error != QNetworkReply::NoError) { ui->downloadInfo->setText(tr("Error: ") + m_reply->errorString()); + } } void DownloadItem::updateDownload() @@ -352,7 +377,7 @@ void DownloadItem::updateDownload() qDebug() << __FUNCTION__ ; #endif if (ui->progressBar->maximum() == 0 && m_outputFile.isOpen() && m_reply->isFinished()) { - downloadProgress(0,0); + downloadProgress(0, 0); finished(); } } diff --git a/src/downloads/downloaditem.h b/src/downloads/downloaditem.h index bbd9292a0..a9ab0836f 100644 --- a/src/downloads/downloaditem.h +++ b/src/downloads/downloaditem.h @@ -33,8 +33,9 @@ #include #include -namespace Ui { - class DownloadItem; +namespace Ui +{ +class DownloadItem; } class DownloadManager; diff --git a/src/downloads/downloadmanager.cpp b/src/downloads/downloadmanager.cpp index fdfc4022d..20cd77323 100644 --- a/src/downloads/downloadmanager.cpp +++ b/src/downloads/downloadmanager.cpp @@ -36,8 +36,9 @@ DownloadManager::DownloadManager(QWidget* parent) setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint); ui->setupUi(this); #ifdef Q_WS_WIN - if (QtWin::isCompositionEnabled()) + if (QtWin::isCompositionEnabled()) { QtWin::extendFrameIntoClientArea(this); + } #endif ui->clearButton->setIcon(QIcon::fromTheme("edit-clear")); qz_centerWidgetOnScreen(this); @@ -49,36 +50,37 @@ DownloadManager::DownloadManager(QWidget* parent) loadSettings(); #ifdef W7API - if (QtWin::isRunningWindows7()) + if (QtWin::isRunningWindows7()) { win7.init(this->winId()); + } #endif } void DownloadManager::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("DownloadManager"); m_downloadPath = settings.value("defaultDownloadPath", "").toString(); m_lastDownloadPath = settings.value("lastDownloadPath", QDir::homePath() + "/").toString(); m_closeOnFinish = settings.value("CloseManagerOnFinish", false).toBool(); m_useNativeDialog = settings.value("useNativeDialog", - #ifdef Q_WS_WIN +#ifdef Q_WS_WIN false - #else +#else true - #endif - ).toBool(); +#endif + ).toBool(); settings.endGroup(); } void DownloadManager::show() { - m_timer.start(1000*2, this); + m_timer.start(1000 * 2, this); QWidget::show(); } -void DownloadManager::resizeEvent(QResizeEvent *e) +void DownloadManager::resizeEvent(QResizeEvent* e) { QWidget::resizeEvent(e); emit resized(size()); @@ -105,33 +107,36 @@ void DownloadManager::timerEvent(QTimerEvent* event) } for (int i = 0; i < ui->list->count(); i++) { DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); - if (!downItem || (downItem && downItem->isCancelled()) || !downItem->isDownloading()) + if (!downItem || (downItem && downItem->isCancelled()) || !downItem->isDownloading()) { continue; + } progresses.append(downItem->progress()); remTimes.append(downItem->remainingTime()); speeds.append(downItem->currentSpeed()); } - if (remTimes.isEmpty()) + if (remTimes.isEmpty()) { return; + } QTime remaining; - foreach (QTime time, remTimes) { - if (time > remaining) + foreach(QTime time, remTimes) { + if (time > remaining) { remaining = time; + } } int progress = 0; - foreach (int prog, progresses) - progress+=prog; + foreach(int prog, progresses) + progress += prog; progress = progress / progresses.count(); double speed = 0.00; - foreach (double spee, speeds) - speed+=spee; + foreach(double spee, speeds) + speed += spee; - ui->speedLabel->setText(tr("%1% of %2 files (%3) %4 remaining").arg(QString::number(progress),QString::number(progresses.count()), - DownloadItem::currentSpeedToString(speed), - DownloadItem::remaingTimeToString(remaining))); + ui->speedLabel->setText(tr("%1% of %2 files (%3) %4 remaining").arg(QString::number(progress), QString::number(progresses.count()), + DownloadItem::currentSpeedToString(speed), + DownloadItem::remaingTimeToString(remaining))); setWindowTitle(QString::number(progress) + tr("% - Download Manager")); #ifdef W7API if (QtWin::isRunningWindows7()) { @@ -139,8 +144,10 @@ void DownloadManager::timerEvent(QTimerEvent* event) win7.setProgressState(win7.Normal); } #endif - } else + } + else { QWidget::timerEvent(event); + } } void DownloadManager::clearList() @@ -148,10 +155,12 @@ void DownloadManager::clearList() QList items; for (int i = 0; i < ui->list->count(); i++) { DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); - if (!downItem) + if (!downItem) { continue; - if (downItem->isDownloading()) + } + if (downItem->isDownloading()) { continue; + } items.append(downItem); } qDeleteAll(items); @@ -164,18 +173,19 @@ void DownloadManager::download(const QNetworkRequest &request, bool askWhatToDo) void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo) { - if (reply->url().scheme() == "qupzilla") + if (reply->url().scheme() == "qupzilla") { return; + } DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog); - connect(h, SIGNAL(itemCreated(QListWidgetItem*,DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*,DownloadItem*))); + connect(h, SIGNAL(itemCreated(QListWidgetItem*, DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*, DownloadItem*))); h->setDownloadManager(this); h->setListWidget(ui->list); h->handleUnsupportedContent(reply, askWhatToDo); } -void DownloadManager::itemCreated(QListWidgetItem *item, DownloadItem *downItem) +void DownloadManager::itemCreated(QListWidgetItem* item, DownloadItem* downItem) { connect(downItem, SIGNAL(deleteItem(DownloadItem*)), this, SLOT(deleteItem(DownloadItem*))); connect(downItem, SIGNAL(downloadFinished(bool)), this, SLOT(downloadFinished(bool))); @@ -193,8 +203,9 @@ void DownloadManager::downloadFinished(bool success) bool downloadingAllFilesFinished = true; for (int i = 0; i < ui->list->count(); i++) { DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); - if (!downItem || (downItem && downItem->isCancelled()) || !downItem->isDownloading()) + if (!downItem || (downItem && downItem->isCancelled()) || !downItem->isDownloading()) { continue; + } downloadingAllFilesFinished = false; } @@ -214,27 +225,31 @@ void DownloadManager::downloadFinished(bool success) win7.setProgressState(win7.NoProgress); } #endif - if (m_closeOnFinish) + if (m_closeOnFinish) { close(); + } } } void DownloadManager::deleteItem(DownloadItem* item) { - if (item && !item->isDownloading()) + if (item && !item->isDownloading()) { delete item; + } } bool DownloadManager::canClose() { - if (m_isClosing) + if (m_isClosing) { return true; + } bool isDownloading = false; for (int i = 0; i < ui->list->count(); i++) { DownloadItem* downItem = qobject_cast(ui->list->itemWidget(ui->list->item(i))); - if (!downItem) + if (!downItem) { continue; + } if (downItem->isDownloading()) { isDownloading = true; break; @@ -247,9 +262,9 @@ bool DownloadManager::canClose() void DownloadManager::closeEvent(QCloseEvent* e) { if (mApp->windowCount() == 0) { // No main windows -> we are going to quit - if (!canClose()){ + if (!canClose()) { QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Warning"), - tr("Are you sure to quit? All uncompleted downloads will be cancelled!"), QMessageBox::Yes | QMessageBox::No); + tr("Are you sure to quit? All uncompleted downloads will be cancelled!"), QMessageBox::Yes | QMessageBox::No); if (button != QMessageBox::Yes) { e->ignore(); return; diff --git a/src/downloads/downloadmanager.h b/src/downloads/downloadmanager.h index 3ee829f01..99630e63e 100644 --- a/src/downloads/downloadmanager.h +++ b/src/downloads/downloadmanager.h @@ -35,8 +35,9 @@ #include "ecwin7.h" -namespace Ui { - class DownloadManager; +namespace Ui +{ +class DownloadManager; } class DownloadItem; @@ -81,7 +82,7 @@ private: #endif void timerEvent(QTimerEvent* event); void closeEvent(QCloseEvent* e); - void resizeEvent(QResizeEvent *e); + void resizeEvent(QResizeEvent* e); Ui::DownloadManager* ui; NetworkManager* m_networkManager; diff --git a/src/downloads/downloadoptionsdialog.cpp b/src/downloads/downloadoptionsdialog.cpp index 79a0a5f1d..917dce987 100644 --- a/src/downloads/downloadoptionsdialog.cpp +++ b/src/downloads/downloadoptionsdialog.cpp @@ -23,7 +23,7 @@ DownloadOptionsDialog::DownloadOptionsDialog(const QString &fileName, const QPix , ui(new Ui::DownloadOptionsDialog) { ui->setupUi(this); - ui->fileName->setText(""+fileName+""); + ui->fileName->setText("" + fileName + ""); ui->fileIcon->setPixmap(fileIcon); ui->fileType->setText(mimeType); ui->fromServer->setText(url.host()); @@ -37,10 +37,12 @@ DownloadOptionsDialog::DownloadOptionsDialog(const QString &fileName, const QPix void DownloadOptionsDialog::emitDialogFinished(int status) { if (status != 0) { - if (ui->radioOpen->isChecked()) + if (ui->radioOpen->isChecked()) { status = 1; - else if (ui->radioSave->isChecked()) + } + else if (ui->radioSave->isChecked()) { status = 2; + } } emit dialogFinished(status); } diff --git a/src/downloads/downloadoptionsdialog.h b/src/downloads/downloadoptionsdialog.h index de6bf76cc..fec5c4326 100644 --- a/src/downloads/downloadoptionsdialog.h +++ b/src/downloads/downloadoptionsdialog.h @@ -22,8 +22,9 @@ #include #include -namespace Ui { - class DownloadOptionsDialog; +namespace Ui +{ +class DownloadOptionsDialog; } class DownloadOptionsDialog : public QDialog diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index 731fc7b68..9a7813ed8 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -35,8 +35,8 @@ HistoryManager::HistoryManager(QupZilla* mainClass, QWidget* parent) qz_centerWidgetOnScreen(this); ui->deleteB->setShortcut(QKeySequence("Del")); - connect(ui->historyTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); - connect(ui->historyTree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)),this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); + connect(ui->historyTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); + connect(ui->historyTree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); connect(ui->deleteB, SIGNAL(clicked()), this, SLOT(deleteItem())); connect(ui->clearAll, SIGNAL(clicked()), this, SLOT(clearHistory())); @@ -44,7 +44,7 @@ HistoryManager::HistoryManager(QupZilla* mainClass, QWidget* parent) connect(m_historyModel, SIGNAL(historyEntryAdded(HistoryModel::HistoryEntry)), this, SLOT(historyEntryAdded(HistoryModel::HistoryEntry))); connect(m_historyModel, SIGNAL(historyEntryDeleted(HistoryModel::HistoryEntry)), this, SLOT(historyEntryDeleted(HistoryModel::HistoryEntry))); - connect(m_historyModel, SIGNAL(historyEntryEdited(HistoryModel::HistoryEntry,HistoryModel::HistoryEntry)), this, SLOT(historyEntryEdited(HistoryModel::HistoryEntry,HistoryModel::HistoryEntry))); + connect(m_historyModel, SIGNAL(historyEntryEdited(HistoryModel::HistoryEntry, HistoryModel::HistoryEntry)), this, SLOT(historyEntryEdited(HistoryModel::HistoryEntry, HistoryModel::HistoryEntry))); connect(m_historyModel, SIGNAL(historyClear()), ui->historyTree, SLOT(clear())); connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb())); @@ -56,37 +56,43 @@ HistoryManager::HistoryManager(QupZilla* mainClass, QWidget* parent) QupZilla* HistoryManager::getQupZilla() { - if (!p_QupZilla) + if (!p_QupZilla) { p_QupZilla = mApp->getWindow(); + } return p_QupZilla; } void HistoryManager::setMainWindow(QupZilla* window) { - if (window) + if (window) { p_QupZilla = window; + } } void HistoryManager::itemDoubleClicked(QTreeWidgetItem* item) { - if (!item || item->text(1).isEmpty()) + if (!item || item->text(1).isEmpty()) { return; + } getQupZilla()->tabWidget()->addView(QUrl(item->text(1))); } void HistoryManager::loadInNewTab() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { getQupZilla()->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab); + } } void HistoryManager::contextMenuRequested(const QPoint &position) { - if (!ui->historyTree->itemAt(position)) + if (!ui->historyTree->itemAt(position)) { return; + } QString link = ui->historyTree->itemAt(position)->text(1); - if (link.isEmpty()) + if (link.isEmpty()) { return; + } QMenu menu; menu.addAction(tr("Open link in actual tab"), getQupZilla(), SLOT(loadActionUrl()))->setData(link); @@ -95,16 +101,17 @@ void HistoryManager::contextMenuRequested(const QPoint &position) //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu.exec(p); } void HistoryManager::deleteItem() { QApplication::setOverrideCursor(Qt::WaitCursor); - foreach (QTreeWidgetItem* item, ui->historyTree->selectedItems()) { - if (!item) + foreach(QTreeWidgetItem * item, ui->historyTree->selectedItems()) { + if (!item) { return; + } if (!item->parent()) { for (int i = 0; i < item->childCount(); i++) { @@ -113,7 +120,8 @@ void HistoryManager::deleteItem() m_historyModel->deleteHistoryEntry(id); } ui->historyTree->deleteItem(item); - } else { + } + else { int id = item->whatsThis(1).toInt(); m_historyModel->deleteHistoryEntry(id); } @@ -129,21 +137,26 @@ void HistoryManager::historyEntryAdded(const HistoryModel::HistoryEntry &entry) QDate date = entry.date.date(); QString localDate; - if (date == todayDate) + if (date == todayDate) { localDate = tr("Today"); - else if (date >= startOfWeekDate) + } + else if (date >= startOfWeekDate) { localDate = tr("This Week"); - else if (date.month() == todayDate.month()) + } + else if (date.month() == todayDate.month()) { localDate = tr("This Month"); - else + } + else { localDate = QString("%1 %2").arg(HistoryModel::titleCaseLocalizedMonth(date.month()), QString::number(date.year())); + } QTreeWidgetItem* item = new QTreeWidgetItem(); QTreeWidgetItem* parentItem; QList findParent = ui->historyTree->findItems(localDate, 0); if (findParent.count() == 1) { parentItem = findParent.at(0); - } else { + } + else { parentItem = new QTreeWidgetItem(); parentItem->setText(0, localDate); parentItem->setIcon(0, QIcon(":/icons/menu/history_entry.png")); @@ -163,11 +176,13 @@ void HistoryManager::historyEntryAdded(const HistoryModel::HistoryEntry &entry) void HistoryManager::historyEntryDeleted(const HistoryModel::HistoryEntry &entry) { QList list = ui->historyTree->allItems(); - foreach (QTreeWidgetItem* item, list) { - if (!item) + foreach(QTreeWidgetItem * item, list) { + if (!item) { continue; - if (item->whatsThis(1).toInt() != entry.id) + } + if (item->whatsThis(1).toInt() != entry.id) { continue; + } ui->historyTree->deleteItem(item); return; } @@ -182,9 +197,10 @@ void HistoryManager::historyEntryEdited(const HistoryModel::HistoryEntry &before void HistoryManager::clearHistory() { QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"), - tr("Are you sure to delete all history?"), QMessageBox::Yes | QMessageBox::No); - if (button != QMessageBox::Yes) + tr("Are you sure to delete all history?"), QMessageBox::Yes | QMessageBox::No); + if (button != QMessageBox::Yes) { return; + } m_historyModel->clearHistory(); m_historyModel->optimizeHistory(); @@ -200,27 +216,32 @@ void HistoryManager::refreshTable() QSqlQuery query; query.exec("SELECT title, url, id, date FROM history ORDER BY date DESC"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); int id = query.value(2).toInt(); QDate date = QDateTime::fromMSecsSinceEpoch(query.value(3).toLongLong()).date(); QString localDate; - if (date == todayDate) + if (date == todayDate) { localDate = tr("Today"); - else if (date >= startOfWeekDate) + } + else if (date >= startOfWeekDate) { localDate = tr("This Week"); - else if (date.month() == todayDate.month()) + } + else if (date.month() == todayDate.month()) { localDate = tr("This Month"); - else + } + else { localDate = QString("%1 %2").arg(HistoryModel::titleCaseLocalizedMonth(date.month()), QString::number(date.year())); + } QTreeWidgetItem* item = new QTreeWidgetItem(); QList findParent = ui->historyTree->findItems(localDate, 0); if (findParent.count() == 1) { item = new QTreeWidgetItem(findParent.at(0)); - }else{ + } + else { QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->historyTree); newParent->setText(0, localDate); newParent->setIcon(0, QIcon(":/icons/menu/history_entry.png")); @@ -253,12 +274,13 @@ void HistoryManager::search(const QString &searchText) refreshTable(); ui->historyTree->setUpdatesEnabled(false); - QList items = ui->historyTree->findItems("*"+searchText+"*", Qt::MatchRecursive | Qt::MatchWildcard); + QList items = ui->historyTree->findItems("*" + searchText + "*", Qt::MatchRecursive | Qt::MatchWildcard); QList foundItems; - foreach(QTreeWidgetItem* fitem, items) { - if (fitem->text(1).isEmpty()) + foreach(QTreeWidgetItem * fitem, items) { + if (fitem->text(1).isEmpty()) { continue; + } QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, fitem->text(0)); item->setText(1, fitem->text(1)); @@ -274,8 +296,9 @@ void HistoryManager::search(const QString &searchText) void HistoryManager::optimizeDb() { BrowsingLibrary* b = qobject_cast(parentWidget()->parentWidget()); - if (!b) + if (!b) { return; + } b->optimizeDatabase(); } diff --git a/src/history/historymanager.h b/src/history/historymanager.h index 2ebe41c98..7600e0b3d 100644 --- a/src/history/historymanager.h +++ b/src/history/historymanager.h @@ -24,8 +24,9 @@ #include "historymodel.h" -namespace Ui { - class HistoryManager; +namespace Ui +{ +class HistoryManager; } class QupZilla; diff --git a/src/history/historymodel.cpp b/src/history/historymodel.cpp index 049d0ad89..5eded2a1a 100644 --- a/src/history/historymodel.cpp +++ b/src/history/historymodel.cpp @@ -30,20 +30,23 @@ HistoryModel::HistoryModel(QupZilla* mainClass, QObject* parent) void HistoryModel::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); - m_isSaving = settings.value("allowHistory",true).toBool(); + m_isSaving = settings.value("allowHistory", true).toBool(); settings.endGroup(); } int HistoryModel::addHistoryEntry(const QString &url, QString &title) { - if (!m_isSaving) + if (!m_isSaving) { return -2; - if (url.startsWith("file://") || url.startsWith("qupzilla:") || title.contains(tr("Failed loading page")) || url.isEmpty() || url.contains("about:blank") ) + } + if (url.startsWith("file://") || url.startsWith("qupzilla:") || title.contains(tr("Failed loading page")) || url.isEmpty() || url.contains("about:blank")) { return -1; - if (title == "") - title=tr("No Named Page"); + } + if (title == "") { + title = tr("No Named Page"); + } QSqlQuery query; query.prepare("SELECT id FROM history WHERE url=?"); @@ -64,7 +67,8 @@ int HistoryModel::addHistoryEntry(const QString &url, QString &title) entry.url = url; entry.title = title; emit historyEntryAdded(entry); - } else { + } + else { int id = query.value(0).toInt(); query.prepare("UPDATE history SET count = count + 1, date=?, title=? WHERE url=?"); query.bindValue(0, QDateTime::currentMSecsSinceEpoch()); @@ -87,8 +91,9 @@ int HistoryModel::addHistoryEntry(const QString &url, QString &title) int HistoryModel::addHistoryEntry(WebView* view) { - if (!m_isSaving) + if (!m_isSaving) { return -2; + } QString url = view->url().toEncoded(); QString title = view->title(); @@ -101,8 +106,9 @@ bool HistoryModel::deleteHistoryEntry(int index) query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?"); query.bindValue(0, index); query.exec(); - if (!query.next()) + if (!query.next()) { return false; + } HistoryEntry entry; entry.id = query.value(0).toInt(); entry.count = query.value(1).toInt(); @@ -151,7 +157,7 @@ QList HistoryModel::mostVisited(int count) QList list; QSqlQuery query; query.exec(QString("SELECT count, date, id, title, url FROM history ORDER BY count DESC LIMIT %1").arg(count)); - while(query.next()) { + while (query.next()) { HistoryEntry entry; entry.count = query.value(0).toInt(); entry.date = query.value(1).toDateTime(); diff --git a/src/history/webhistoryinterface.cpp b/src/history/webhistoryinterface.cpp index 0d6f34ede..3cd879805 100644 --- a/src/history/webhistoryinterface.cpp +++ b/src/history/webhistoryinterface.cpp @@ -19,7 +19,7 @@ #include "mainapplication.h" #include "historymodel.h" -WebHistoryInterface::WebHistoryInterface(QObject *parent) : +WebHistoryInterface::WebHistoryInterface(QObject* parent) : QWebHistoryInterface(parent) { } diff --git a/src/history/webhistoryinterface.h b/src/history/webhistoryinterface.h index bc1d857e2..426e7ac78 100644 --- a/src/history/webhistoryinterface.h +++ b/src/history/webhistoryinterface.h @@ -25,7 +25,7 @@ class WebHistoryInterface : public QWebHistoryInterface { Q_OBJECT public: - explicit WebHistoryInterface(QObject *parent = 0); + explicit WebHistoryInterface(QObject* parent = 0); void addHistoryEntry(const QString &url); bool historyContains(const QString &url) const; diff --git a/src/main.cpp b/src/main.cpp index c437f2366..b8a3a2bce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ #include "commandlineoptions.h" #include "mainapplication.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { Q_INIT_RESOURCE(icons); Q_INIT_RESOURCE(html); @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) if (argc > 1) { CommandLineOptions cmd(argc, argv); cmdActions = cmd.getActions(); - foreach (CommandLineOptions::ActionPair pair, cmdActions) { + foreach(CommandLineOptions::ActionPair pair, cmdActions) { switch (pair.action) { case CommandLineOptions::ExitAction: return 1; @@ -51,8 +51,9 @@ int main(int argc, char *argv[]) MainApplication app(cmdActions, argc, argv); if (app.isExited()) { - if (argc == 1) + if (argc == 1) { std::cout << "QupZilla already running - activating existing window" << std::endl; + } return 1; } diff --git a/src/navigation/locationbar.cpp b/src/navigation/locationbar.cpp index a48b840a3..67e2d5edf 100644 --- a/src/navigation/locationbar.cpp +++ b/src/navigation/locationbar.cpp @@ -113,10 +113,12 @@ void LocationBar::urlEnter() if (urlToLoad.isEmpty()) { QUrl guessedUrl = WebView::guessUrlFromString(text()); - if (!guessedUrl.isEmpty()) + if (!guessedUrl.isEmpty()) { urlToLoad = guessedUrl; - else + } + else { urlToLoad = text(); + } } m_webView->load(urlToLoad); @@ -132,8 +134,9 @@ void LocationBar::textEdit() void LocationBar::showGoButton() { - if (m_goButton->isVisible()) + if (m_goButton->isVisible()) { return; + } m_rssIconVisible = m_rssIcon->isVisible(); @@ -144,8 +147,9 @@ void LocationBar::showGoButton() void LocationBar::hideGoButton() { - if (!m_goButton->isVisible()) + if (!m_goButton->isVisible()) { return; + } m_rssIcon->setVisible(m_rssIconVisible); m_bookmarkIcon->show(); @@ -179,10 +183,11 @@ void LocationBar::showRSSIcon(bool state) void LocationBar::showUrl(const QUrl &url, bool empty) { - if (hasFocus() || (url.isEmpty() && empty)) + if (hasFocus() || (url.isEmpty() && empty)) { return; + } - if (url.toEncoded()!=text()) { + if (url.toEncoded() != text()) { setText(url.toEncoded()); setCursorPosition(0); } @@ -199,8 +204,9 @@ void LocationBar::siteIconChanged() if (icon_.isNull()) { clearIcon(); - } else { - m_siteIcon->setIcon(QIcon(icon_.pixmap(16,16))); + } + else { + m_siteIcon->setIcon(QIcon(icon_.pixmap(16, 16))); } } @@ -219,8 +225,9 @@ void LocationBar::setPrivacy(bool state) void LocationBar::focusOutEvent(QFocusEvent* e) { QLineEdit::focusOutEvent(e); - if (!selectedText().isEmpty() && e->reason() != Qt::TabFocusReason) + if (!selectedText().isEmpty() && e->reason() != Qt::TabFocusReason) { return; + } setCursorPosition(0); hideGoButton(); } @@ -251,13 +258,15 @@ void LocationBar::dropEvent(QDropEvent* event) void LocationBar::mouseDoubleClickEvent(QMouseEvent* event) { - if (event->button() == Qt::LeftButton && m_locationBarSettings->selectAllOnDoubleClick) + if (event->button() == Qt::LeftButton && m_locationBarSettings->selectAllOnDoubleClick) { selectAll(); - else + } + else { QLineEdit::mouseDoubleClickEvent(event); + } } -void LocationBar::keyPressEvent(QKeyEvent *event) +void LocationBar::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { setText(m_webView->url().toEncoded()); @@ -265,11 +274,13 @@ void LocationBar::keyPressEvent(QKeyEvent *event) return; } - QString localDomain = tr(".co.uk","Append domain name on ALT key = Should be different for every country"); - if (event->key() == Qt::Key_Control && m_locationBarSettings->addComWithCtrl && !text().endsWith(".com")) //Disabled for a while + QString localDomain = tr(".co.uk", "Append domain name on ALT key = Should be different for every country"); + if (event->key() == Qt::Key_Control && m_locationBarSettings->addComWithCtrl && !text().endsWith(".com")) { //Disabled for a while setText(text().append(".com")); - if (event->key() == Qt::Key_Alt && m_locationBarSettings->addCountryWithAlt && !text().endsWith(localDomain) && !text().endsWith("/")) + } + if (event->key() == Qt::Key_Alt && m_locationBarSettings->addCountryWithAlt && !text().endsWith(localDomain) && !text().endsWith("/")) { setText(text().append(localDomain)); + } QLineEdit::keyPressEvent(event); } diff --git a/src/navigation/locationbarsettings.cpp b/src/navigation/locationbarsettings.cpp index 95768f0f3..122b0c874 100644 --- a/src/navigation/locationbarsettings.cpp +++ b/src/navigation/locationbarsettings.cpp @@ -30,16 +30,17 @@ LocationBarSettings::LocationBarSettings() LocationBarSettings* LocationBarSettings::instance() { - if (!s_instance) + if (!s_instance) { s_instance = new LocationBarSettings(); + } return s_instance; } void LocationBarSettings::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("AddressBar"); - selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick",true).toBool(); - addComWithCtrl = settings.value("AddComDomainWithCtrlKey",false).toBool(); - addCountryWithAlt = settings.value("AddCountryDomainWithAltKey",true).toBool(); + selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick", true).toBool(); + addComWithCtrl = settings.value("AddComDomainWithCtrlKey", false).toBool(); + addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool(); } diff --git a/src/navigation/locationcompleter.cpp b/src/navigation/locationcompleter.cpp index 2532330e8..2acaa6200 100644 --- a/src/navigation/locationcompleter.cpp +++ b/src/navigation/locationcompleter.cpp @@ -34,7 +34,7 @@ LocationCompleter::LocationCompleter(QObject* parent) : treeView->header()->hide(); treeView->header()->setStretchLastSection(false); treeView->header()->setResizeMode(0, QHeaderView::Stretch); - treeView->header()->resizeSection(1,0); + treeView->header()->resizeSection(1, 0); setCompletionMode(QCompleter::PopupCompletion); setCaseSensitivity(Qt::CaseInsensitive); @@ -56,50 +56,56 @@ QStringList LocationCompleter::splitPath(const QString &path) const QStringList returned = QCompleter::splitPath(path); QStringList returned2; QSqlQuery query; - query.exec("SELECT url FROM history WHERE title LIKE '%"+path+"%' OR url LIKE '%"+path+"%' ORDER BY count DESC LIMIT 1"); + query.exec("SELECT url FROM history WHERE title LIKE '%" + path + "%' OR url LIKE '%" + path + "%' ORDER BY count DESC LIMIT 1"); if (query.next()) { QString url = query.value(0).toString(); bool titleSearching = false; - if (!url.contains(path)) + if (!url.contains(path)) { titleSearching = true; - QString prefix = url.mid(0,url.indexOf(path)); - foreach (QString string, returned) { - if (titleSearching) + } + QString prefix = url.mid(0, url.indexOf(path)); + foreach(QString string, returned) { + if (titleSearching) { returned2.append(url); - else - returned2.append(prefix+string); + } + else { + returned2.append(prefix + string); + } } return returned2; - } else { - foreach (QString string, returned) - returned2.append("http://www.google.com/search?client=qupzilla&q=" + string); + } + else { + foreach(QString string, returned) + returned2.append("http://www.google.com/search?client=qupzilla&q=" + string); return returned2; } #endif } -void LocationCompleter::refreshCompleter(QString string) +void LocationCompleter::refreshCompleter(const QString &string) { int limit; - if (string.size() < 3) + if (string.size() < 3) { limit = 25; - else + } + else { limit = 15; + } QSqlQuery query; - query.exec("SELECT title, url FROM history WHERE title LIKE '%"+string+"%' OR url LIKE '%"+string+"%' ORDER BY count DESC LIMIT "+QString::number(limit)); + query.exec("SELECT title, url FROM history WHERE title LIKE '%" + string + "%' OR url LIKE '%" + string + "%' ORDER BY count DESC LIMIT " + QString::number(limit)); int i = 0; QStandardItemModel* cModel = qobject_cast(model()); QTreeView* treeView = qobject_cast(popup()); cModel->clear(); - while(query.next()) { + while (query.next()) { QStandardItem* iconText = new QStandardItem(); QStandardItem* findUrl = new QStandardItem(); QString url = query.value(1).toUrl().toEncoded(); - iconText->setIcon(_iconForUrl(query.value(1).toUrl()).pixmap(16,16)); - iconText->setText(query.value(0).toString().replace("\n","").append("\n"+url)); + iconText->setIcon(_iconForUrl(query.value(1).toUrl()).pixmap(16, 16)); + iconText->setText(query.value(0).toString().replace("\n", "").append("\n" + url)); findUrl->setText(url); QList items; @@ -124,12 +130,14 @@ void LocationCompleter::refreshCompleter(QString string) // } treeView->header()->setResizeMode(0, QHeaderView::Stretch); - treeView->header()->resizeSection(1,0); + treeView->header()->resizeSection(1, 0); - if (i>6) + if (i > 6) { popup()->setMinimumHeight(190); - else + } + else { popup()->setMinimumHeight(0); + } popup()->setUpdatesEnabled(true); } diff --git a/src/navigation/locationcompleter.h b/src/navigation/locationcompleter.h index da9b79798..c0a5e71ab 100644 --- a/src/navigation/locationcompleter.h +++ b/src/navigation/locationcompleter.h @@ -40,7 +40,7 @@ public: signals: public slots: - void refreshCompleter(QString string); + void refreshCompleter(const QString &string); }; diff --git a/src/navigation/locationpopup.cpp b/src/navigation/locationpopup.cpp index 1295d00b3..e864aebb2 100644 --- a/src/navigation/locationpopup.cpp +++ b/src/navigation/locationpopup.cpp @@ -17,8 +17,8 @@ * ============================================================ */ #include "locationpopup.h" LocationPopup::LocationPopup(QWidget* parent) - :QAbstractItemView() - ,m_parent(parent) + : QAbstractItemView() + , m_parent(parent) { setWindowFlags(Qt::Popup); } @@ -26,7 +26,7 @@ LocationPopup::LocationPopup(QWidget* parent) void LocationPopup::show() { QPoint p = m_parent->mapToGlobal(QPoint(0, 0)); - move( (p.x() ), (p.y() + m_parent->height())); + move((p.x()), (p.y() + m_parent->height())); resize(m_parent->width(), 100); QAbstractItemView::show(); } diff --git a/src/navigation/navigationbar.cpp b/src/navigation/navigationbar.cpp index 93989e2f9..6627e6e7e 100644 --- a/src/navigation/navigationbar.cpp +++ b/src/navigation/navigationbar.cpp @@ -23,7 +23,7 @@ #include "reloadstopbutton.h" #include "webhistorywrapper.h" -NavigationBar::NavigationBar(QupZilla *mainClass, QWidget *parent) +NavigationBar::NavigationBar(QupZilla* mainClass, QWidget* parent) : QWidget(parent) , p_QupZilla(mainClass) { @@ -120,7 +120,8 @@ void NavigationBar::setSplitterSizes(int locationBar, int websearchBar) if (locationBar == 0) { int splitterWidth = m_navigationSplitter->width(); sizes << (int)((double)splitterWidth * .80) << (int)((double)splitterWidth * .20); - } else { + } + else { sizes << locationBar << websearchBar; } @@ -139,8 +140,9 @@ void NavigationBar::showStopButton() void NavigationBar::aboutToShowHistoryBackMenu() { - if (!m_menuBack || !p_QupZilla->weView()) + if (!m_menuBack || !p_QupZilla->weView()) { return; + } m_menuBack->clear(); QWebHistory* history = p_QupZilla->weView()->history(); @@ -148,7 +150,7 @@ void NavigationBar::aboutToShowHistoryBackMenu() int count = 0; QUrl lastUrl = history->currentItem().url(); - for (int i = curindex-1; i >= 0; i--) { + for (int i = curindex - 1; i >= 0; i--) { QWebHistoryItem item = history->itemAt(i); if (item.isValid() && lastUrl != item.url()) { QString title = item.title(); @@ -156,14 +158,15 @@ void NavigationBar::aboutToShowHistoryBackMenu() title.truncate(40); title += ".."; } - QAction* action = m_menuBack->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex())); + QAction* action = m_menuBack->addAction(_iconForUrl(item.url()), title, this, SLOT(goAtHistoryIndex())); action->setData(i); lastUrl = item.url(); } count++; - if (count == 20) + if (count == 20) { break; + } } m_menuBack->addSeparator(); @@ -172,8 +175,9 @@ void NavigationBar::aboutToShowHistoryBackMenu() void NavigationBar::aboutToShowHistoryNextMenu() { - if (!m_menuForward || !p_QupZilla->weView()) + if (!m_menuForward || !p_QupZilla->weView()) { return; + } m_menuForward->clear(); QWebHistory* history = p_QupZilla->weView()->history(); @@ -181,7 +185,7 @@ void NavigationBar::aboutToShowHistoryNextMenu() int count = 0; QUrl lastUrl = history->currentItem().url(); - for (int i = curindex+1; i < history->count(); i++) { + for (int i = curindex + 1; i < history->count(); i++) { QWebHistoryItem item = history->itemAt(i); if (item.isValid() && lastUrl != item.url()) { QString title = item.title(); @@ -189,14 +193,15 @@ void NavigationBar::aboutToShowHistoryNextMenu() title.truncate(40); title += ".."; } - QAction* action = m_menuForward->addAction(_iconForUrl(item.url()),title, this, SLOT(goAtHistoryIndex())); + QAction* action = m_menuForward->addAction(_iconForUrl(item.url()), title, this, SLOT(goAtHistoryIndex())); action->setData(i); lastUrl = item.url(); } count++; - if (count == 20) + if (count == 20) { break; + } } m_menuForward->addSeparator(); @@ -221,8 +226,9 @@ void NavigationBar::goAtHistoryIndex() void NavigationBar::refreshHistory() { - if (mApp->isClosing() || p_QupZilla->isClosing()) + if (mApp->isClosing() || p_QupZilla->isClosing()) { return; + } QWebHistory* history = p_QupZilla->weView()->page()->history(); m_buttonBack->setEnabled(WebHistoryWrapper::canGoBack(history)); diff --git a/src/navigation/navigationbar.h b/src/navigation/navigationbar.h index b0bf90e34..0b038368b 100644 --- a/src/navigation/navigationbar.h +++ b/src/navigation/navigationbar.h @@ -31,7 +31,7 @@ class NavigationBar : public QWidget { Q_OBJECT public: - explicit NavigationBar(QupZilla* mainClass, QWidget *parent = 0); + explicit NavigationBar(QupZilla* mainClass, QWidget* parent = 0); ~NavigationBar(); void setSplitterSizes(int locationBar, int websearchBar); diff --git a/src/navigation/reloadstopbutton.cpp b/src/navigation/reloadstopbutton.cpp index 4e02cd957..33eec4f38 100644 --- a/src/navigation/reloadstopbutton.cpp +++ b/src/navigation/reloadstopbutton.cpp @@ -17,7 +17,7 @@ * ============================================================ */ #include "reloadstopbutton.h" -ReloadStopButton::ReloadStopButton(QWidget *parent) : +ReloadStopButton::ReloadStopButton(QWidget* parent) : QWidget(parent) { QHBoxLayout* lay = new QHBoxLayout(this); diff --git a/src/navigation/reloadstopbutton.h b/src/navigation/reloadstopbutton.h index cbb165a70..b4be041d1 100644 --- a/src/navigation/reloadstopbutton.h +++ b/src/navigation/reloadstopbutton.h @@ -26,7 +26,7 @@ class ReloadStopButton : public QWidget { Q_OBJECT public: - explicit ReloadStopButton(QWidget *parent = 0); + explicit ReloadStopButton(QWidget* parent = 0); ~ReloadStopButton(); void showStopButton(); diff --git a/src/navigation/websearchbar.cpp b/src/navigation/websearchbar.cpp index 86c5e6caa..ccb0162b3 100644 --- a/src/navigation/websearchbar.cpp +++ b/src/navigation/websearchbar.cpp @@ -99,12 +99,13 @@ void WebSearchBar::setupEngines() QString activeEngine = m_searchManager->startingEngineName(); - if (m_boxSearchType->allItems().count() != 0) + if (m_boxSearchType->allItems().count() != 0) { activeEngine = m_activeEngine.name; + } m_boxSearchType->clearItems(); - foreach (SearchEngine en, m_searchManager->allEngines()) { + foreach(SearchEngine en, m_searchManager->allEngines()) { ButtonWithMenu::Item item; item.icon = en.icon; item.text = en.name; @@ -114,8 +115,9 @@ void WebSearchBar::setupEngines() m_boxSearchType->addItem(item); - if (item.text == activeEngine) + if (item.text == activeEngine) { m_boxSearchType->setCurrentItem(item); + } } connect(m_searchManager, SIGNAL(enginesChanged()), this, SLOT(setupEngines())); @@ -140,22 +142,25 @@ void WebSearchBar::search() p_QupZilla->weView()->setFocus(); } -void WebSearchBar::completeMenuWithAvailableEngines(QMenu *menu) +void WebSearchBar::completeMenuWithAvailableEngines(QMenu* menu) { WebView* view = p_QupZilla->weView(); QWebFrame* frame = view->webPage()->mainFrame(); QWebElementCollection elements = frame->documentElement().findAll(QLatin1String("link[rel=search]")); - foreach (QWebElement element, elements) { - if (element.attribute("type") != "application/opensearchdescription+xml") + foreach(QWebElement element, elements) { + if (element.attribute("type") != "application/opensearchdescription+xml") { continue; + } QString url = view->url().resolved(element.attribute("href")).toString(); QString title = element.attribute("title"); - if (url.isEmpty()) + if (url.isEmpty()) { continue; - if (title.isEmpty()) + } + if (title.isEmpty()) { title = view->title(); + } menu->addAction(view->icon(), tr("Add %1 ...").arg(title), this, SLOT(addEngineFromAction()))->setData(url); } diff --git a/src/network/networkmanager.cpp b/src/network/networkmanager.cpp index 998fa0dbf..80c4cb54e 100644 --- a/src/network/networkmanager.cpp +++ b/src/network/networkmanager.cpp @@ -37,9 +37,9 @@ NetworkManager::NetworkManager(QupZilla* mainClass, QObject* parent) , m_qupzillaSchemeHandler(new QupZillaSchemeHandler) , m_ignoreAllWarnings(false) { - connect(this, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authentication(QNetworkReply*, QAuthenticator* ))); - connect(this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthentication(QNetworkProxy,QAuthenticator*))); - connect(this, SIGNAL(sslErrors(QNetworkReply*,QList)), this, SLOT(sslError(QNetworkReply*,QList))); + connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, SLOT(authentication(QNetworkReply*, QAuthenticator*))); + connect(this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy, QAuthenticator*)), this, SLOT(proxyAuthentication(QNetworkProxy, QAuthenticator*))); + connect(this, SIGNAL(sslErrors(QNetworkReply*, QList)), this, SLOT(sslError(QNetworkReply*, QList))); connect(this, SIGNAL(finished(QNetworkReply*)), this, SLOT(setSSLConfiguration(QNetworkReply*))); m_proxyFactory = new NetworkProxyFactory(); @@ -49,13 +49,13 @@ NetworkManager::NetworkManager(QupZilla* mainClass, QObject* parent) void NetworkManager::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Browser-Settings"); if (settings.value("AllowLocalCache", true).toBool()) { m_diskCache = mApp->networkCache(); - m_diskCache->setCacheDirectory(mApp->getActiveProfilPath()+"/networkcache"); - m_diskCache->setMaximumCacheSize(settings.value("MaximumCacheSize",50).toInt() * 1024*1024); //MegaBytes + m_diskCache->setCacheDirectory(mApp->getActiveProfilPath() + "/networkcache"); + m_diskCache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes setCache(m_diskCache); } m_doNotTrack = settings.value("DoNotTrack", false).toBool(); @@ -75,23 +75,26 @@ void NetworkManager::loadSettings() m_proxyFactory->loadSettings(); } -void NetworkManager::setSSLConfiguration(QNetworkReply *reply) +void NetworkManager::setSSLConfiguration(QNetworkReply* reply) { if (!reply->sslConfiguration().isNull()) { QSslCertificate cert = reply->sslConfiguration().peerCertificate(); - if (!cert.isValid()) + if (!cert.isValid()) { return; + } QNetworkRequest request = reply->request(); QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); WebPage* webPage = (WebPage*)(v.value()); v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102)); WebView* webView = (WebView*)(v.value()); - if (!webPage || !webView) + if (!webPage || !webView) { return; + } - if (webView->url().host() == reply->url().host()) - webPage->setSSLCertificate( cert ); + if (webView->url().host() == reply->url().host()) { + webPage->setSSLCertificate(cert); + } } } @@ -105,19 +108,22 @@ void NetworkManager::sslError(QNetworkReply* reply, QList errors) QNetworkRequest request = reply->request(); QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100)); WebPage* webPage = (WebPage*)(v.value()); - if (!webPage) + if (!webPage) { return; + } QString title = tr("SSL Certificate Error!"); QString text1 = tr("The page you trying to access has following errors in SSL Certificate:"); QStringList actions; - foreach (QSslError error, errors) { - if (m_localCerts.contains(error.certificate())) + foreach(QSslError error, errors) { + if (m_localCerts.contains(error.certificate())) { continue; - if (error.error() == QSslError::NoError) //Weird behavior on Windows + } + if (error.error() == QSslError::NoError) { //Weird behavior on Windows continue; + } QSslCertificate cert = error.certificate(); actions.append(tr("Organization: ") + CertificateInfoWidget::clearCertSpecialSymbols(cert.subjectInfo(QSslCertificate::Organization))); @@ -134,13 +140,15 @@ void NetworkManager::sslError(QNetworkReply* reply, QList errors) // message, QMessageBox::Yes | QMessageBox::No); // if (button != QMessageBox::Yes) // return; - if (!webPage->javaScriptConfirm(webPage->mainFrame(), message)) + if (!webPage->javaScriptConfirm(webPage->mainFrame(), message)) { return; + } } - foreach (QSslError error, errors) { - if (m_localCerts.contains(error.certificate())) + foreach(QSslError error, errors) { + if (m_localCerts.contains(error.certificate())) { continue; + } addLocalCertificate(error.certificate()); } @@ -190,19 +198,22 @@ void NetworkManager::authentication(QNetworkReply* reply, QAuthenticator* auth) emit wantsFocus(reply->url()); //Do not save when private browsing is enabled - if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) + if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { save->setVisible(false); + } - if (!dialog->exec() == QDialog::Accepted) + if (!dialog->exec() == QDialog::Accepted) { return; + } auth->setUser(user->text()); auth->setPassword(pass->text()); - if (save->isChecked()) + if (save->isChecked()) { fill->addEntry(reply->url(), user->text(), pass->text()); + } } -void NetworkManager::proxyAuthentication(const QNetworkProxy &proxy, QAuthenticator *auth) +void NetworkManager::proxyAuthentication(const QNetworkProxy &proxy, QAuthenticator* auth) { QDialog* dialog = new QDialog(p_QupZilla); dialog->setWindowTitle(tr("Proxy authorization required")); @@ -231,8 +242,9 @@ void NetworkManager::proxyAuthentication(const QNetworkProxy &proxy, QAuthentica formLa->addRow(passLab, pass); formLa->addWidget(box); - if (!dialog->exec() == QDialog::Accepted) + if (!dialog->exec() == QDialog::Accepted) { return; + } auth->setUser(user->text()); auth->setPassword(pass->text()); } @@ -240,35 +252,41 @@ void NetworkManager::proxyAuthentication(const QNetworkProxy &proxy, QAuthentica QNetworkReply* NetworkManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData) { if (op == PostOperation && outgoingData) { - QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); - mApp->autoFill()->post(request, outgoingDataByteArray); + QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); + mApp->autoFill()->post(request, outgoingDataByteArray); } QNetworkRequest req = request; QNetworkReply* reply = 0; - if (m_doNotTrack) + if (m_doNotTrack) { req.setRawHeader("DNT", "1"); + } req.setRawHeader("Accept-Language", m_acceptLanguage); //SchemeHandlers - if (req.url().scheme() == "qupzilla") + if (req.url().scheme() == "qupzilla") { reply = m_qupzillaSchemeHandler->createRequest(op, req, outgoingData); - if (reply) + } + if (reply) { return reply; + } req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); - if (req.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt() == QNetworkRequest::PreferNetwork) + if (req.attribute(QNetworkRequest::CacheLoadControlAttribute).toInt() == QNetworkRequest::PreferNetwork) { req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + } // Adblock if (op == QNetworkAccessManager::GetOperation) { - if (!m_adblockNetwork) + if (!m_adblockNetwork) { m_adblockNetwork = AdBlockManager::instance()->network(); + } reply = m_adblockNetwork->block(req); - if (reply) + if (reply) { return reply; + } } reply = QNetworkAccessManager::createRequest(op, req, outgoingData); @@ -288,8 +306,9 @@ void NetworkManager::removeLocalCertificate(const QSslCertificate &cert) QDirIterator it(mApp->getActiveProfilPath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); while (it.hasNext()) { QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex); - if (!filePath.contains(certFileName)) + if (!filePath.contains(certFileName)) { continue; + } QFile file(filePath); file.remove(); @@ -299,15 +318,17 @@ void NetworkManager::removeLocalCertificate(const QSslCertificate &cert) void NetworkManager::addLocalCertificate(const QSslCertificate &cert) { - if (!cert.isValid()) + if (!cert.isValid()) { return; + } m_localCerts.append(cert); QSslSocket::addDefaultCaCertificate(cert); QDir dir(mApp->getActiveProfilPath()); - if (!dir.exists("certificates")) + if (!dir.exists("certificates")) { dir.mkdir("certificates"); + } QString fileName = qz_ensureUniqueFilename(mApp->getActiveProfilPath() + "certificates/" + CertificateInfoWidget::certificateItemText(cert).remove(" ") + ".crt"); QFile file(fileName); @@ -336,7 +357,7 @@ void NetworkManager::loadCertificates() //CA Certificates m_caCerts = QSslSocket::defaultCaCertificates(); - foreach (QString path, m_certPaths) { + foreach(QString path, m_certPaths) { #ifdef Q_WS_WIN // Used from Qt 4.7.4 qsslcertificate.cpp and modified because QSslCertificate::fromPath // is kind of a bugged on Windows, it does work only with full path to cert file @@ -344,12 +365,14 @@ void NetworkManager::loadCertificates() QDirIterator it(path, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); while (it.hasNext()) { QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex); - if (!filePath.endsWith(".crt")) + if (!filePath.endsWith(".crt")) { continue; + } QFile file(filePath); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { m_caCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem); + } } #else m_caCerts += QSslCertificate::fromPath(path + "/*.crt", QSsl::Pem, QRegExp::Wildcard); @@ -357,19 +380,21 @@ void NetworkManager::loadCertificates() } //Local Certificates #ifdef Q_WS_WIN - int startIndex = 0; - QDirIterator it_(mApp->getActiveProfilPath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); - while (it_.hasNext()) { - QString filePath = startIndex == 0 ? it_.next() : it_.next().mid(startIndex); - if (!filePath.endsWith(".crt")) - continue; - - QFile file(filePath); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - m_localCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem); + int startIndex = 0; + QDirIterator it_(mApp->getActiveProfilPath() + "certificates", QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); + while (it_.hasNext()) { + QString filePath = startIndex == 0 ? it_.next() : it_.next().mid(startIndex); + if (!filePath.endsWith(".crt")) { + continue; } + + QFile file(filePath); + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_localCerts += QSslCertificate::fromData(file.readAll(), QSsl::Pem); + } + } #else - m_localCerts += QSslCertificate::fromPath(mApp->getActiveProfilPath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard); + m_localCerts += QSslCertificate::fromPath(mApp->getActiveProfilPath() + "certificates/*.crt", QSsl::Pem, QRegExp::Wildcard); #endif QSslSocket::setDefaultCaCertificates(m_caCerts + m_localCerts); diff --git a/src/network/networkmanager.h b/src/network/networkmanager.h index 6e71fab85..bdd5de663 100644 --- a/src/network/networkmanager.h +++ b/src/network/networkmanager.h @@ -69,7 +69,7 @@ signals: private slots: void authentication(QNetworkReply* reply, QAuthenticator* auth); - void proxyAuthentication(const QNetworkProxy& proxy,QAuthenticator* auth); + void proxyAuthentication(const QNetworkProxy &proxy, QAuthenticator* auth); void sslError(QNetworkReply* reply, QList errors); void setSSLConfiguration(QNetworkReply* reply); diff --git a/src/network/networkmanagerproxy.cpp b/src/network/networkmanagerproxy.cpp index 996900bc1..757b2e82b 100644 --- a/src/network/networkmanagerproxy.cpp +++ b/src/network/networkmanagerproxy.cpp @@ -22,11 +22,12 @@ #include "cookiejar.h" #include "mainapplication.h" -NetworkManagerProxy::NetworkManagerProxy(QupZilla* mainClass, QObject* parent) : - QNetworkAccessManager(parent) - ,p_QupZilla(mainClass) - ,m_view(0) - ,m_page(0) +NetworkManagerProxy::NetworkManagerProxy(QupZilla* mainClass, QObject* parent) + : QNetworkAccessManager(parent) + , p_QupZilla(mainClass) + , m_view(0) + , m_page(0) + , m_manager(0) { setCookieJar(mApp->cookieJar()); } @@ -34,7 +35,7 @@ NetworkManagerProxy::NetworkManagerProxy(QupZilla* mainClass, QObject* parent) : void NetworkManagerProxy::populateNetworkRequest(QNetworkRequest &request) { qDebug() << __FUNCTION__ << "called"; - QVariant variant = qVariantFromValue((void *) m_page); + QVariant variant = qVariantFromValue((void*) m_page); request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant); } @@ -44,7 +45,7 @@ void NetworkManagerProxy::setPrimaryNetworkAccessManager(NetworkManager* manager m_manager = manager; connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*))); - connect(this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); + connect(this, SIGNAL(proxyAuthenticationRequired(QNetworkProxy, QAuthenticator*)), manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy, QAuthenticator*))); connect(this, SIGNAL(finished(QNetworkReply*)), manager, SIGNAL(finished(QNetworkReply*))); connect(this, SIGNAL(sslErrors(QNetworkReply*, const QList&)), manager, SIGNAL(sslErrors(QNetworkReply*, const QList&))); } diff --git a/src/network/networkproxyfactory.cpp b/src/network/networkproxyfactory.cpp index e2f7aea80..37eb0f9e5 100644 --- a/src/network/networkproxyfactory.cpp +++ b/src/network/networkproxyfactory.cpp @@ -18,14 +18,15 @@ #include "networkproxyfactory.h" #include "mainapplication.h" -NetworkProxyFactory::NetworkProxyFactory() : - QNetworkProxyFactory() +NetworkProxyFactory::NetworkProxyFactory() + : QNetworkProxyFactory() + , m_proxyPreference(SystemProxy) { } void NetworkProxyFactory::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Web-Proxy"); m_proxyPreference = ProxyPreference(settings.value("UseProxy", SystemProxy).toInt()); m_proxyType = QNetworkProxy::ProxyType(settings.value("ProxyType", QNetworkProxy::HttpProxy).toInt()); @@ -41,8 +42,9 @@ QList NetworkProxyFactory::queryProxy(const QNetworkProxyQuery &q { QNetworkProxy proxy; - if (m_proxyExceptions.contains(query.url().host(), Qt::CaseInsensitive)) + if (m_proxyExceptions.contains(query.url().host(), Qt::CaseInsensitive)) { proxy.setType(QNetworkProxy::NoProxy); + } switch (m_proxyPreference) { case SystemProxy: diff --git a/src/network/qupzillaschemehandler.cpp b/src/network/qupzillaschemehandler.cpp index 69dcab540..d5a39e29e 100644 --- a/src/network/qupzillaschemehandler.cpp +++ b/src/network/qupzillaschemehandler.cpp @@ -35,14 +35,15 @@ QNetworkReply* QupZillaSchemeHandler::createRequest(QNetworkAccessManager::Opera { Q_UNUSED(outgoingData) - if (op != QNetworkAccessManager::GetOperation) + if (op != QNetworkAccessManager::GetOperation) { return 0; + } QupZillaSchemeReply* reply = new QupZillaSchemeReply(request); return reply; } -QupZillaSchemeReply::QupZillaSchemeReply(const QNetworkRequest &req, QObject *parent) +QupZillaSchemeReply::QupZillaSchemeReply(const QNetworkRequest &req, QObject* parent) : QNetworkReply(parent) { setOperation(QNetworkAccessManager::GetOperation); @@ -56,7 +57,8 @@ QupZillaSchemeReply::QupZillaSchemeReply(const QNetworkRequest &req, QObject *pa QTimer::singleShot(0, this, SLOT(loadPage())); open(QIODevice::ReadOnly); - } else { + } + else { setError(QNetworkReply::HostNotFoundError, tr("Not Found")); QTimer::singleShot(0, this, SLOT(delayedFinish())); } @@ -65,12 +67,15 @@ QupZillaSchemeReply::QupZillaSchemeReply(const QNetworkRequest &req, QObject *pa void QupZillaSchemeReply::loadPage() { QTextStream stream(&m_buffer); - if (m_pageName == "about") + if (m_pageName == "about") { stream << aboutPage(); - else if (m_pageName == "reportbug") + } + else if (m_pageName == "reportbug") { stream << reportbugPage(); - else if (m_pageName == "start") + } + else if (m_pageName == "start") { stream << startPage(); + } stream.flush(); m_buffer.reset(); @@ -97,7 +102,7 @@ qint64 QupZillaSchemeReply::bytesAvailable() const return m_buffer.bytesAvailable() + QNetworkReply::bytesAvailable(); } -qint64 QupZillaSchemeReply::readData(char *data, qint64 maxSize) +qint64 QupZillaSchemeReply::readData(char* data, qint64 maxSize) { return m_buffer.read(data, maxSize); } @@ -178,17 +183,17 @@ QString QupZillaSchemeReply::aboutPage() page.replace("%MAIN-DEVELOPER-TEXT%", authorString(QupZilla::AUTHOR, "nowrep@gmail.com")); page.replace("%CONTRIBUTORS%", tr("Contributors")); page.replace("%CONTRIBUTORS-TEXT%", authorString("Daniele Cocca", "jmc@chakra-project.org") + "
    " + - authorString("Jan Rajnoha", "honza.rajny@hotmail.com") - ); + authorString("Jan Rajnoha", "honza.rajny@hotmail.com") + ); page.replace("%TRANSLATORS%", tr("Translators")); page.replace("%TRANSLATORS-TEXT%", authorString("Heimen Stoffels", "vistausss@gmail.com") + " (Dutch)
    " + - authorString("Peter Vacula", "pvacula1989@gmail.com") + " (Slovak)
    " + - authorString("Ján Ďanovský", "dagsoftware@yahoo.com") + " (Slovak)
    " + - authorString("Jonathan Hooverman", "jonathan.hooverman@gmail.com") + " (German)
    " + - authorString("Unink-Lio", "unink4451@163.com") + " (Chinese)
    " + - authorString("Federico Fabiani", "federico.fabiani85@gmail.com") + " (Italy)
    " + - authorString("Francesco Marinucci", "framarinucci@gmail.com") + " (Italy)" - ); + authorString("Peter Vacula", "pvacula1989@gmail.com") + " (Slovak)
    " + + authorString("Ján Ďanovský", "dagsoftware@yahoo.com") + " (Slovak)
    " + + authorString("Jonathan Hooverman", "jonathan.hooverman@gmail.com") + " (German)
    " + + authorString("Unink-Lio", "unink4451@163.com") + " (Chinese)
    " + + authorString("Federico Fabiani", "federico.fabiani85@gmail.com") + " (Italy)
    " + + authorString("Francesco Marinucci", "framarinucci@gmail.com") + " (Italy)" + ); return page; } diff --git a/src/network/qupzillaschemehandler.h b/src/network/qupzillaschemehandler.h index 2f0a7e513..1bb0a8e41 100644 --- a/src/network/qupzillaschemehandler.h +++ b/src/network/qupzillaschemehandler.h @@ -48,7 +48,7 @@ public: virtual qint64 bytesAvailable() const; protected: - virtual qint64 readData(char *data, qint64 maxSize); + virtual qint64 readData(char* data, qint64 maxSize); virtual void abort() { } private slots: diff --git a/src/opensearch/editsearchengine.cpp b/src/opensearch/editsearchengine.cpp index 9b84f8a67..7a450abd5 100644 --- a/src/opensearch/editsearchengine.cpp +++ b/src/opensearch/editsearchengine.cpp @@ -82,8 +82,9 @@ void EditSearchEngine::hideIconLabels() void EditSearchEngine::chooseIcon() { QString path = QFileDialog::getOpenFileName(this, tr("Choose icon...")); - if (path.isEmpty()) + if (path.isEmpty()) { return; + } setIcon(QIcon(path)); } diff --git a/src/opensearch/editsearchengine.h b/src/opensearch/editsearchengine.h index 29112144a..12aba66f9 100644 --- a/src/opensearch/editsearchengine.h +++ b/src/opensearch/editsearchengine.h @@ -21,8 +21,9 @@ #include #include -namespace Ui { - class EditSearchEngine; +namespace Ui +{ +class EditSearchEngine; } class EditSearchEngine : public QDialog diff --git a/src/opensearch/opensearchengine.cpp b/src/opensearch/opensearchengine.cpp index 799eb57a2..b2adb6a3e 100644 --- a/src/opensearch/opensearchengine.cpp +++ b/src/opensearch/opensearchengine.cpp @@ -98,7 +98,7 @@ /*! Constructs an engine with a given \a parent. */ -OpenSearchEngine::OpenSearchEngine(QObject *parent) +OpenSearchEngine::OpenSearchEngine(QObject* parent) : QObject(parent) , m_searchMethod(QLatin1String("get")) , m_suggestionsMethod(QLatin1String("get")) @@ -116,8 +116,9 @@ OpenSearchEngine::OpenSearchEngine(QObject *parent) */ OpenSearchEngine::~OpenSearchEngine() { - if (m_scriptEngine) + if (m_scriptEngine) { m_scriptEngine->deleteLater(); + } } QString OpenSearchEngine::parseTemplate(const QString &searchTerm, const QString &searchTemplate) @@ -219,16 +220,18 @@ void OpenSearchEngine::setSearchUrlTemplate(const QString &searchUrlTemplate) */ QUrl OpenSearchEngine::searchUrl(const QString &searchTerm) const { - if (m_searchUrlTemplate.isEmpty()) + if (m_searchUrlTemplate.isEmpty()) { return QUrl(); + } QUrl retVal = QUrl::fromEncoded(parseTemplate(searchTerm, m_searchUrlTemplate).toUtf8()); if (m_searchMethod != QLatin1String("post")) { Parameters::const_iterator end = m_searchParameters.constEnd(); Parameters::const_iterator i = m_searchParameters.constBegin(); - for (; i != end; ++i) + for (; i != end; ++i) { retVal.addQueryItem(i->first, parseTemplate(searchTerm, i->second)); + } } return retVal; @@ -277,16 +280,18 @@ QUrl OpenSearchEngine::suggestionsUrl(const QString &searchTerm) const return QUrl(s); } - if (m_suggestionsUrlTemplate.isEmpty()) + if (m_suggestionsUrlTemplate.isEmpty()) { return QUrl(); + } QUrl retVal = QUrl::fromEncoded(parseTemplate(searchTerm, m_suggestionsUrlTemplate).toUtf8()); if (m_suggestionsMethod != QLatin1String("post")) { Parameters::const_iterator end = m_suggestionsParameters.constEnd(); Parameters::const_iterator i = m_suggestionsParameters.constBegin(); - for (; i != end; ++i) + for (; i != end; ++i) { retVal.addQueryItem(i->first, parseTemplate(searchTerm, i->second)); + } } return retVal; @@ -338,8 +343,9 @@ QString OpenSearchEngine::searchMethod() const void OpenSearchEngine::setSearchMethod(const QString &method) { QString requestMethod = method.toLower(); - if (!m_requestMethods.contains(requestMethod)) + if (!m_requestMethods.contains(requestMethod)) { return; + } m_searchMethod = requestMethod; } @@ -356,8 +362,9 @@ QString OpenSearchEngine::suggestionsMethod() const void OpenSearchEngine::setSuggestionsMethod(const QString &method) { QString requestMethod = method.toLower(); - if (!m_requestMethods.contains(requestMethod)) + if (!m_requestMethods.contains(requestMethod)) { return; + } m_suggestionsMethod = requestMethod; } @@ -386,27 +393,30 @@ void OpenSearchEngine::setImageUrl(const QString &imageUrl) void OpenSearchEngine::loadImage() const { - if (!m_networkAccessManager || m_imageUrl.isEmpty()) + if (!m_networkAccessManager || m_imageUrl.isEmpty()) { return; + } - QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(QUrl::fromEncoded(m_imageUrl.toUtf8()))); + QNetworkReply* reply = m_networkAccessManager->get(QNetworkRequest(QUrl::fromEncoded(m_imageUrl.toUtf8()))); connect(reply, SIGNAL(finished()), this, SLOT(imageObtained())); } void OpenSearchEngine::imageObtained() { - QNetworkReply *reply = qobject_cast(sender()); + QNetworkReply* reply = qobject_cast(sender()); - if (!reply) + if (!reply) { return; + } QByteArray response = reply->readAll(); reply->close(); reply->deleteLater(); - if (response.isEmpty()) + if (response.isEmpty()) { return; + } m_image.loadFromData(response); emit imageChanged(); @@ -423,8 +433,9 @@ void OpenSearchEngine::imageObtained() */ QImage OpenSearchEngine::image() const { - if (m_image.isNull()) + if (m_image.isNull()) { loadImage(); + } return m_image; } @@ -499,8 +510,9 @@ QByteArray OpenSearchEngine::getSuggestionsParameters() QStringList parameters; Parameters::const_iterator end = m_suggestionsParameters.constEnd(); Parameters::const_iterator i = m_suggestionsParameters.constBegin(); - for (; i != end; ++i) + for (; i != end; ++i) { parameters.append(i->first + QLatin1String("=") + i->second); + } QByteArray data = parameters.join(QLatin1String("&")).toUtf8(); @@ -509,13 +521,15 @@ QByteArray OpenSearchEngine::getSuggestionsParameters() void OpenSearchEngine::requestSuggestions(const QString &searchTerm) { - if (searchTerm.isEmpty() || !providesSuggestions()) + if (searchTerm.isEmpty() || !providesSuggestions()) { return; + } Q_ASSERT(m_networkAccessManager); - if (!m_networkAccessManager) + if (!m_networkAccessManager) { return; + } if (m_suggestionsReply) { m_suggestionsReply->disconnect(this); @@ -527,12 +541,14 @@ void OpenSearchEngine::requestSuggestions(const QString &searchTerm) Q_ASSERT(m_requestMethods.contains(m_suggestionsMethod)); if (m_suggestionsMethod == QLatin1String("get")) { m_suggestionsReply = m_networkAccessManager->get(QNetworkRequest(suggestionsUrl(searchTerm))); - } else { + } + else { QStringList parameters; Parameters::const_iterator end = m_suggestionsParameters.constEnd(); Parameters::const_iterator i = m_suggestionsParameters.constBegin(); - for (; i != end; ++i) + for (; i != end; ++i) { parameters.append(i->first + QLatin1String("=") + i->second); + } QByteArray data = parameters.join(QLatin1String("&")).toUtf8(); m_suggestionsReply = m_networkAccessManager->post(QNetworkRequest(suggestionsUrl(searchTerm)), data); @@ -553,8 +569,9 @@ void OpenSearchEngine::requestSuggestions(const QString &searchTerm) */ void OpenSearchEngine::requestSearchResults(const QString &searchTerm) { - if (!m_delegate || searchTerm.isEmpty()) + if (!m_delegate || searchTerm.isEmpty()) { return; + } Q_ASSERT(m_requestMethods.contains(m_searchMethod)); @@ -566,8 +583,9 @@ void OpenSearchEngine::requestSearchResults(const QString &searchTerm) QStringList parameters; Parameters::const_iterator end = m_searchParameters.constEnd(); Parameters::const_iterator i = m_searchParameters.constBegin(); - for (; i != end; ++i) + for (; i != end; ++i) { parameters.append(i->first + QLatin1String("=") + i->second); + } data = parameters.join(QLatin1String("&")).toUtf8(); } @@ -584,23 +602,28 @@ void OpenSearchEngine::suggestionsObtained() m_suggestionsReply->deleteLater(); m_suggestionsReply = 0; - if (response.isEmpty()) + if (response.isEmpty()) { return; + } - if (!response.startsWith(QLatin1Char('[')) || !response.endsWith(QLatin1Char(']'))) + if (!response.startsWith(QLatin1Char('[')) || !response.endsWith(QLatin1Char(']'))) { return; + } - if (!m_scriptEngine) + if (!m_scriptEngine) { m_scriptEngine = new QScriptEngine(); + } // Evaluate the JSON response using QtScript. - if (!m_scriptEngine->canEvaluate(response)) + if (!m_scriptEngine->canEvaluate(response)) { return; + } QScriptValue responseParts = m_scriptEngine->evaluate(response); - if (!responseParts.property(1).isArray()) + if (!responseParts.property(1).isArray()) { return; + } QStringList suggestionsList; qScriptValueToSequence(responseParts.property(1), suggestionsList); @@ -615,12 +638,12 @@ void OpenSearchEngine::suggestionsObtained() It is required for network operations: loading external images and requesting contextual suggestions. */ -QNetworkAccessManager *OpenSearchEngine::networkAccessManager() const +QNetworkAccessManager* OpenSearchEngine::networkAccessManager() const { return m_networkAccessManager; } -void OpenSearchEngine::setNetworkAccessManager(QNetworkAccessManager *networkAccessManager) +void OpenSearchEngine::setNetworkAccessManager(QNetworkAccessManager* networkAccessManager) { m_networkAccessManager = networkAccessManager; } @@ -632,12 +655,12 @@ void OpenSearchEngine::setNetworkAccessManager(QNetworkAccessManager *networkAcc It can be currently supplied to provide a custom behaviour ofthe requetSearchResults() method. The default implementation does nothing. */ -OpenSearchEngineDelegate *OpenSearchEngine::delegate() const +OpenSearchEngineDelegate* OpenSearchEngine::delegate() const { return m_delegate; } -void OpenSearchEngine::setDelegate(OpenSearchEngineDelegate *delegate) +void OpenSearchEngine::setDelegate(OpenSearchEngineDelegate* delegate) { m_delegate = delegate; } diff --git a/src/opensearch/opensearchengine.h b/src/opensearch/opensearchengine.h index ad930ffa0..3dcb34d53 100644 --- a/src/opensearch/opensearchengine.h +++ b/src/opensearch/opensearchengine.h @@ -71,9 +71,9 @@ public: Q_PROPERTY(bool providesSuggestions READ providesSuggestions) Q_PROPERTY(QString imageUrl READ imageUrl WRITE setImageUrl) Q_PROPERTY(bool valid READ isValid) - Q_PROPERTY(QNetworkAccessManager *networkAccessManager READ networkAccessManager WRITE setNetworkAccessManager) + Q_PROPERTY(QNetworkAccessManager* networkAccessManager READ networkAccessManager WRITE setNetworkAccessManager) - OpenSearchEngine(QObject *parent = 0); + OpenSearchEngine(QObject* parent = 0); ~OpenSearchEngine(); QString name() const; @@ -117,11 +117,11 @@ public: QString getSuggestionsUrl(); QByteArray getSuggestionsParameters(); - QNetworkAccessManager *networkAccessManager() const; - void setNetworkAccessManager(QNetworkAccessManager *networkAccessManager); + QNetworkAccessManager* networkAccessManager() const; + void setNetworkAccessManager(QNetworkAccessManager* networkAccessManager); - OpenSearchEngineDelegate *delegate() const; - void setDelegate(OpenSearchEngineDelegate *delegate); + OpenSearchEngineDelegate* delegate() const; + void setDelegate(OpenSearchEngineDelegate* delegate); bool operator==(const OpenSearchEngine &other) const; bool operator<(const OpenSearchEngine &other) const; @@ -157,12 +157,12 @@ private: QMap m_requestMethods; - QNetworkAccessManager *m_networkAccessManager; - QNetworkReply *m_suggestionsReply; + QNetworkAccessManager* m_networkAccessManager; + QNetworkReply* m_suggestionsReply; - QScriptEngine *m_scriptEngine; + QScriptEngine* m_scriptEngine; - OpenSearchEngineDelegate *m_delegate; + OpenSearchEngineDelegate* m_delegate; }; #endif // OPENSEARCHENGINE_H diff --git a/src/opensearch/opensearchreader.cpp b/src/opensearch/opensearchreader.cpp index a5ac73a9e..f7c44bbd7 100644 --- a/src/opensearch/opensearchreader.cpp +++ b/src/opensearch/opensearchreader.cpp @@ -82,65 +82,73 @@ OpenSearchReader::OpenSearchReader() \note The lifetime of the returned OpenSearchEngine object is up to the user. The object should be deleted once it is not used anymore to avoid memory leaks. */ -OpenSearchEngine *OpenSearchReader::read(QIODevice *device) +OpenSearchEngine* OpenSearchReader::read(QIODevice* device) { clear(); - if (!device->isOpen()) + if (!device->isOpen()) { device->open(QIODevice::ReadOnly); + } setDevice(device); return read(); } -OpenSearchEngine *OpenSearchReader::read() +OpenSearchEngine* OpenSearchReader::read() { - OpenSearchEngine *engine = new OpenSearchEngine(); - m_searchXml = device()->peek(1024*5); + OpenSearchEngine* engine = new OpenSearchEngine(); + m_searchXml = device()->peek(1024 * 5); - while (!isStartElement() && !atEnd()) + while (!isStartElement() && !atEnd()) { readNext(); + } if (!m_searchXml.contains(QLatin1String("http://a9.com/-/spec/opensearch/1.1/"))) { - raiseError(QObject::tr("The file is not an OpenSearch 1.1 file.")); - return engine; - } + raiseError(QObject::tr("The file is not an OpenSearch 1.1 file.")); + return engine; + } while (!atEnd()) { readNext(); - if (!isStartElement()) + if (!isStartElement()) { continue; + } if (name() == QLatin1String("ShortName") || name() == QLatin1String("os:ShortName")) { engine->setName(readElementText()); - } else if (name() == QLatin1String("Description") || name() == QLatin1String("os:Description")) { + } + else if (name() == QLatin1String("Description") || name() == QLatin1String("os:Description")) { engine->setDescription(readElementText()); - } else if (name() == QLatin1String("Url") || name() == QLatin1String("os:Url")) { + } + else if (name() == QLatin1String("Url") || name() == QLatin1String("os:Url")) { QString type = attributes().value(QLatin1String("type")).toString(); QString url = attributes().value(QLatin1String("template")).toString(); QString method = attributes().value(QLatin1String("method")).toString(); if (type == QLatin1String("application/x-suggestions+json") - && !engine->suggestionsUrlTemplate().isEmpty()) + && !engine->suggestionsUrlTemplate().isEmpty()) { continue; + } if ((type.isEmpty() - || type == QLatin1String("text/html") - || type == QLatin1String("application/xhtml+xml")) - && !engine->searchUrlTemplate().isEmpty()) + || type == QLatin1String("text/html") + || type == QLatin1String("application/xhtml+xml")) + && !engine->searchUrlTemplate().isEmpty()) { continue; + } - if (url.isEmpty()) + if (url.isEmpty()) { continue; + } QList parameters; readNext(); while (!isEndElement() || (name() != QLatin1String("Url") && name() != QLatin1String("os:Url"))) { - if (!isStartElement() || (name() != QLatin1String("Param") && name() != QLatin1String("Parameter") - && name() != QLatin1String("os:Param") && name() != QLatin1String("os:Parameter") )) { + if (!isStartElement() || (name() != QLatin1String("Param") && name() != QLatin1String("Parameter") + && name() != QLatin1String("os:Param") && name() != QLatin1String("os:Parameter"))) { readNext(); continue; } @@ -148,33 +156,38 @@ OpenSearchEngine *OpenSearchReader::read() QString key = attributes().value(QLatin1String("name")).toString(); QString value = attributes().value(QLatin1String("value")).toString(); - if (!key.isEmpty() && !value.isEmpty()) + if (!key.isEmpty() && !value.isEmpty()) { parameters.append(OpenSearchEngine::Parameter(key, value)); + } - while (!isEndElement()) + while (!isEndElement()) { readNext(); + } } if (type == QLatin1String("application/x-suggestions+json")) { engine->setSuggestionsUrlTemplate(url); engine->setSuggestionsParameters(parameters); engine->setSuggestionsMethod(method); - } else if (type.isEmpty() || type == QLatin1String("text/html") || type == QLatin1String("application/xhtml+xml")) { + } + else if (type.isEmpty() || type == QLatin1String("text/html") || type == QLatin1String("application/xhtml+xml")) { engine->setSearchUrlTemplate(url); engine->setSearchParameters(parameters); engine->setSearchMethod(method); } - } else if (name() == QLatin1String("Image") || name() == QLatin1String("os:Image")) { - engine->setImageUrl(readElementText()); + } + else if (name() == QLatin1String("Image") || name() == QLatin1String("os:Image")) { + engine->setImageUrl(readElementText()); } if (!engine->name().isEmpty() - && !engine->description().isEmpty() - && !engine->suggestionsUrlTemplate().isEmpty() - && !engine->searchUrlTemplate().isEmpty() - && !engine->imageUrl().isEmpty()) + && !engine->description().isEmpty() + && !engine->suggestionsUrlTemplate().isEmpty() + && !engine->searchUrlTemplate().isEmpty() + && !engine->imageUrl().isEmpty()) { break; + } } return engine; diff --git a/src/opensearch/opensearchreader.h b/src/opensearch/opensearchreader.h index d391bed53..ea29b1453 100644 --- a/src/opensearch/opensearchreader.h +++ b/src/opensearch/opensearchreader.h @@ -45,10 +45,10 @@ class OpenSearchReader : public QXmlStreamReader public: OpenSearchReader(); - OpenSearchEngine *read(QIODevice *device); + OpenSearchEngine* read(QIODevice* device); private: - OpenSearchEngine *read(); + OpenSearchEngine* read(); QString m_searchXml; }; diff --git a/src/opensearch/searchenginesdialog.cpp b/src/opensearch/searchenginesdialog.cpp index 7909f75d1..cbb8513a3 100644 --- a/src/opensearch/searchenginesdialog.cpp +++ b/src/opensearch/searchenginesdialog.cpp @@ -21,7 +21,7 @@ #include "searchenginesmanager.h" #include "mainapplication.h" -SearchEnginesDialog::SearchEnginesDialog(QWidget *parent) +SearchEnginesDialog::SearchEnginesDialog(QWidget* parent) : QDialog(parent) , ui(new Ui::SearchEnginesDialog) { @@ -34,7 +34,7 @@ SearchEnginesDialog::SearchEnginesDialog(QWidget *parent) connect(ui->remove, SIGNAL(clicked()), this, SLOT(removeEngine())); connect(ui->edit, SIGNAL(clicked()), this, SLOT(editEngine())); connect(ui->defaults, SIGNAL(clicked()), this, SLOT(defaults())); - connect(ui->treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(editEngine())); + connect(ui->treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(editEngine())); reloadEngines(); } @@ -44,8 +44,9 @@ void SearchEnginesDialog::addEngine() EditSearchEngine dialog(tr("Add Search Engine"), this); dialog.hideIconLabels(); - if (dialog.exec() != QDialog::Accepted) + if (dialog.exec() != QDialog::Accepted) { return; + } SearchEngine engine; engine.name = dialog.name(); @@ -53,8 +54,9 @@ void SearchEnginesDialog::addEngine() engine.shortcut = dialog.shortcut(); engine.icon = SearchEnginesManager::iconForSearchEngine(dialog.url()); - if (engine.name.isEmpty() || engine.url.isEmpty()) + if (engine.name.isEmpty() || engine.url.isEmpty()) { return; + } QTreeWidgetItem* item = new QTreeWidgetItem(); QVariant v; @@ -71,8 +73,9 @@ void SearchEnginesDialog::addEngine() void SearchEnginesDialog::removeEngine() { QTreeWidgetItem* item = ui->treeWidget->currentItem(); - if (!item || ui->treeWidget->topLevelItemCount() == 1) + if (!item || ui->treeWidget->topLevelItemCount() == 1) { return; + } delete item; } @@ -80,8 +83,9 @@ void SearchEnginesDialog::removeEngine() void SearchEnginesDialog::editEngine() { QTreeWidgetItem* item = ui->treeWidget->currentItem(); - if (!item) + if (!item) { return; + } SearchEngine engine = item->data(0, Qt::UserRole).value(); @@ -92,16 +96,18 @@ void SearchEnginesDialog::editEngine() dialog.setShortcut(engine.shortcut); dialog.setIcon(engine.icon); - if (dialog.exec() != QDialog::Accepted) + if (dialog.exec() != QDialog::Accepted) { return; + } engine.name = dialog.name(); engine.url = dialog.url(); engine.shortcut = dialog.shortcut(); engine.icon = dialog.icon(); - if (engine.name.isEmpty() || engine.url.isEmpty()) + if (engine.name.isEmpty() || engine.url.isEmpty()) { return; + } QVariant v; v.setValue(engine); @@ -122,7 +128,7 @@ void SearchEnginesDialog::reloadEngines() { ui->treeWidget->clear(); - foreach (SearchEngine en, m_manager->allEngines()) { + foreach(SearchEngine en, m_manager->allEngines()) { QTreeWidgetItem* item = new QTreeWidgetItem(); item->setIcon(0, en.icon); item->setText(0, en.name); @@ -137,15 +143,17 @@ void SearchEnginesDialog::reloadEngines() void SearchEnginesDialog::accept() { - if (ui->treeWidget->topLevelItemCount() < 1) + if (ui->treeWidget->topLevelItemCount() < 1) { return; + } QList allEngines; for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++) { QTreeWidgetItem* item = ui->treeWidget->topLevelItem(i); - if (!item) + if (!item) { continue; + } SearchEngine engine = item->data(0, Qt::UserRole).value(); allEngines.append(engine); diff --git a/src/opensearch/searchenginesdialog.h b/src/opensearch/searchenginesdialog.h index aee2f2c28..4d0fd426a 100644 --- a/src/opensearch/searchenginesdialog.h +++ b/src/opensearch/searchenginesdialog.h @@ -20,8 +20,9 @@ #include -namespace Ui { - class SearchEnginesDialog; +namespace Ui +{ +class SearchEnginesDialog; } class SearchEnginesManager; @@ -30,7 +31,7 @@ class SearchEnginesDialog : public QDialog Q_OBJECT public: - explicit SearchEnginesDialog(QWidget *parent = 0); + explicit SearchEnginesDialog(QWidget* parent = 0); ~SearchEnginesDialog(); public slots: @@ -46,7 +47,7 @@ private slots: private: void reloadEngines(); - Ui::SearchEnginesDialog *ui; + Ui::SearchEnginesDialog* ui; SearchEnginesManager* m_manager; }; diff --git a/src/opensearch/searchenginesmanager.cpp b/src/opensearch/searchenginesmanager.cpp index be205fd88..5b9bce0df 100644 --- a/src/opensearch/searchenginesmanager.cpp +++ b/src/opensearch/searchenginesmanager.cpp @@ -27,8 +27,9 @@ QIcon SearchEnginesManager::iconForSearchEngine(const QUrl &url) { QIcon ic = mApp->iconProvider()->iconForDomain(url); - if (ic.isNull()) + if (ic.isNull()) { ic = QIcon(":icons/menu/search-icon.png"); + } return ic; } @@ -38,7 +39,7 @@ SearchEnginesManager::SearchEnginesManager() , m_settingsLoaded(false) , m_saveScheduled(false) { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("SearchEngines"); m_startingEngineName = settings.value("activeEngine", "Google").toString(); settings.endGroup(); @@ -63,15 +64,17 @@ void SearchEnginesManager::loadSettings() m_allEngines.append(en); } - if (m_allEngines.isEmpty()) + if (m_allEngines.isEmpty()) { restoreDefaults(); + } } SearchEngine SearchEnginesManager::engineForShortcut(const QString &shortcut) { - foreach (Engine en, m_allEngines) { - if (en.shortcut == shortcut) + foreach(Engine en, m_allEngines) { + if (en.shortcut == shortcut) { return en; + } } return Engine(); @@ -136,10 +139,11 @@ void SearchEnginesManager::engineChangedImage() { OpenSearchEngine* engine = qobject_cast(sender()); - if (!engine) + if (!engine) { return; + } - foreach (Engine e, m_allEngines) { + foreach(Engine e, m_allEngines) { if (e.name == engine->name() && e.url.contains(engine->searchUrl("%s").toString()) && !engine->image().isNull()) { e.icon = QIcon(QPixmap::fromImage(engine->image())); @@ -165,13 +169,15 @@ void SearchEnginesManager::addEngine(const Engine &engine, bool emitSignal) { ENSURE_LOADED; - if (m_allEngines.contains(engine)) + if (m_allEngines.contains(engine)) { return; + } m_allEngines.append(engine); - if (emitSignal) + if (emitSignal) { emit enginesChanged(); + } } void SearchEnginesManager::addEngine(OpenSearchEngine* engine) @@ -181,10 +187,12 @@ void SearchEnginesManager::addEngine(OpenSearchEngine* engine) Engine en; en.name = engine->name(); en.url = engine->searchUrl("searchstring").toString().replace("searchstring", "%s"); - if (engine->image().isNull()) + if (engine->image().isNull()) { en.icon = iconForSearchEngine(engine->searchUrl("")); - else + } + else { en.icon = QIcon(QPixmap::fromImage(engine->image())); + } en.suggestionsUrl = engine->getSuggestionsUrl(); en.suggestionsParameters = engine->getSuggestionsParameters(); @@ -197,8 +205,9 @@ void SearchEnginesManager::addEngine(const QUrl &url) { ENSURE_LOADED; - if (!url.isValid()) + if (!url.isValid()) { return; + } qApp->setOverrideCursor(Qt::WaitCursor); @@ -212,8 +221,9 @@ void SearchEnginesManager::replyFinished() qApp->restoreOverrideCursor(); QNetworkReply* reply = qobject_cast(sender()); - if (!reply) + if (!reply) { return; + } if (reply->error() != QNetworkReply::NoError) { reply->close(); @@ -250,8 +260,9 @@ void SearchEnginesManager::setActiveEngine(const Engine &engine) { ENSURE_LOADED; - if (!m_allEngines.contains(engine)) + if (!m_allEngines.contains(engine)) { return; + } m_activeEngine = engine; emit activeEngineChanged(); @@ -261,8 +272,9 @@ void SearchEnginesManager::removeEngine(const Engine &engine) { ENSURE_LOADED; - if (!m_allEngines.contains(engine)) + if (!m_allEngines.contains(engine)) { return; + } QSqlQuery query; query.prepare("DELETE FROM search_engines WHERE name=? AND url=?"); @@ -291,13 +303,14 @@ QList SearchEnginesManager::allEngines() void SearchEnginesManager::saveSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("SearchEngines"); settings.setValue("activeEngine", m_activeEngine.name); settings.endGroup(); - if (!m_saveScheduled) + if (!m_saveScheduled) { return; + } // Well, this is not the best implementation to do as this is taking some time. // Actually, it is delaying the quit of app for about a 1 sec on my machine with only @@ -309,7 +322,7 @@ void SearchEnginesManager::saveSettings() QSqlQuery query; query.exec("DELETE FROM search_engines"); - foreach (Engine en, m_allEngines) { + foreach(Engine en, m_allEngines) { query.prepare("INSERT INTO search_engines (name, icon, url, shortcut, suggestionsUrl, suggestionsParameters) VALUES (?, ?, ?, ?, ?, ?)"); query.bindValue(0, en.name); query.bindValue(1, IconProvider::iconToBase64(en.icon)); diff --git a/src/opensearch/searchenginesmanager.h b/src/opensearch/searchenginesmanager.h index 92eef3f1b..de032ca92 100644 --- a/src/opensearch/searchenginesmanager.h +++ b/src/opensearch/searchenginesmanager.h @@ -46,8 +46,7 @@ public: QByteArray suggestionsParameters; - bool operator==(const Engine &other) - { + bool operator==(const Engine &other) const { return (this->name == other.name && this->url == other.url); } diff --git a/src/other/aboutdialog.cpp b/src/other/aboutdialog.cpp index 52fb5857f..4d6d1be97 100644 --- a/src/other/aboutdialog.cpp +++ b/src/other/aboutdialog.cpp @@ -42,10 +42,12 @@ AboutDialog::AboutDialog(QWidget* parent) : void AboutDialog::buttonClicked() { - if (ui->authorsButton->text() == tr("Authors and Contributors")) + if (ui->authorsButton->text() == tr("Authors and Contributors")) { showAuthors(); - else if (ui->authorsButton->text() == tr("< About QupZilla")) + } + else if (ui->authorsButton->text() == tr("< About QupZilla")) { showAbout(); + } } void AboutDialog::showAbout() @@ -58,7 +60,7 @@ void AboutDialog::showAbout() m_aboutHtml.append(tr("

    © %1 %2
    All rights reserved.
    ").arg(QupZilla::COPYRIGHT, QupZilla::AUTHOR)); m_aboutHtml.append(tr("Build time: %1

    ").arg(QupZilla::BUILDTIME)); m_aboutHtml.append(QString("

    %1

    ").arg(QupZilla::WWWADDRESS)); - m_aboutHtml.append("

    "+mApp->getWindow()->weView()->webPage()->userAgentForUrl(QUrl())+"

    "); + m_aboutHtml.append("

    " + mApp->getWindow()->weView()->webPage()->userAgentForUrl(QUrl()) + "

    "); m_aboutHtml.append(""); } ui->textBrowser->setHtml(m_aboutHtml); @@ -72,12 +74,12 @@ void AboutDialog::showAuthors() m_authorsHtml.append(tr("

    Main developers:
    %1 <%2>

    ").arg(QupZilla::AUTHOR, "nowrep@gmail.com")); m_authorsHtml.append(tr("

    Contributors:
    %1

    ").arg("Daniele Cocca
    Jan Rajnoha")); m_authorsHtml.append(tr("

    Translators:
    %1

    ").arg("Heimen Stoffels (Dutch)
    " - "Peter Vacula (Slovakia)
    " - "Jonathan Hooverman (German)
    " - "Unink-Lio (Chinese)
    " - "Federico Fabiani (Italy)
    " - "Francesco Marinucci (Italy)" - )); + "Peter Vacula (Slovakia)
    " + "Jonathan Hooverman (German)
    " + "Unink-Lio (Chinese)
    " + "Federico Fabiani (Italy)
    " + "Francesco Marinucci (Italy)" + )); m_authorsHtml.append(""); } ui->textBrowser->setHtml(m_authorsHtml); diff --git a/src/other/aboutdialog.h b/src/other/aboutdialog.h index b84b736af..3cfa93c6b 100644 --- a/src/other/aboutdialog.h +++ b/src/other/aboutdialog.h @@ -20,8 +20,9 @@ #include -namespace Ui { - class AboutDialog; +namespace Ui +{ +class AboutDialog; } class AboutDialog : public QDialog diff --git a/src/other/browsinglibrary.cpp b/src/other/browsinglibrary.cpp index 95a2efb5f..8e9184d0a 100644 --- a/src/other/browsinglibrary.cpp +++ b/src/other/browsinglibrary.cpp @@ -24,7 +24,7 @@ #include "downloaditem.h" #include "globalfunctions.h" -BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget *parent) +BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget* parent) : QWidget(parent) , ui(new Ui::BrowsingLibrary) , m_historyManager(new HistoryManager(mainClass)) @@ -35,7 +35,7 @@ BrowsingLibrary::BrowsingLibrary(QupZilla* mainClass, QWidget *parent) , m_rssLoaded(false) { ui->setupUi(this); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("BrowsingLibrary"); resize(settings.value("size", QSize(760, 470)).toSize()); settings.endGroup(); @@ -89,10 +89,12 @@ void BrowsingLibrary::currentIndexChanged(int index) void BrowsingLibrary::search() { - if (ui->tabs->current_index() == 0) + if (ui->tabs->current_index() == 0) { m_historyManager->search(ui->searchLine->text()); - else + } + else { m_bookmarksManager->search(ui->searchLine->text()); + } } void BrowsingLibrary::showHistory(QupZilla* mainClass) @@ -141,16 +143,16 @@ void BrowsingLibrary::optimizeDatabase() { mApp->setOverrideCursor(Qt::WaitCursor); QString profilePath = mApp->getActiveProfilPath(); - QString sizeBefore = DownloadItem::fileSizeToString(QFileInfo(profilePath+"browsedata.db").size()); + QString sizeBefore = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); mApp->history()->optimizeHistory(); - QString sizeAfter = DownloadItem::fileSizeToString(QFileInfo(profilePath+"browsedata.db").size()); + QString sizeAfter = DownloadItem::fileSizeToString(QFileInfo(profilePath + "browsedata.db").size()); mApp->restoreOverrideCursor(); QMessageBox::information(this, tr("Database Optimized"), tr("Database successfully optimized.

    Database Size Before: %1
    Database Size After: %2").arg(sizeBefore, sizeAfter)); } -void BrowsingLibrary::closeEvent(QCloseEvent *e) +void BrowsingLibrary::closeEvent(QCloseEvent* e) { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("BrowsingLibrary"); settings.setValue("size", size()); settings.endGroup(); diff --git a/src/other/browsinglibrary.h b/src/other/browsinglibrary.h index 793e36f5a..622c6ce56 100644 --- a/src/other/browsinglibrary.h +++ b/src/other/browsinglibrary.h @@ -22,8 +22,9 @@ #include #include -namespace Ui { - class BrowsingLibrary; +namespace Ui +{ +class BrowsingLibrary; } class HistoryManager; @@ -35,7 +36,7 @@ class BrowsingLibrary : public QWidget Q_OBJECT public: - explicit BrowsingLibrary(QupZilla* mainClass, QWidget *parent = 0); + explicit BrowsingLibrary(QupZilla* mainClass, QWidget* parent = 0); ~BrowsingLibrary(); void showHistory(QupZilla* mainClass); @@ -53,8 +54,8 @@ private slots: void search(); private: - void closeEvent(QCloseEvent *e); - Ui::BrowsingLibrary *ui; + void closeEvent(QCloseEvent* e); + Ui::BrowsingLibrary* ui; HistoryManager* m_historyManager; BookmarksManager* m_bookmarksManager; RSSManager* m_rssManager; diff --git a/src/other/clearprivatedata.cpp b/src/other/clearprivatedata.cpp index 0a8444496..5203631a9 100644 --- a/src/other/clearprivatedata.cpp +++ b/src/other/clearprivatedata.cpp @@ -59,7 +59,7 @@ void ClearPrivateData::dialogAccepted() switch (ui->historyLength->currentIndex()) { case 0: //Later Today - dateTime.setTime(QTime(0,0)); + dateTime.setTime(QTime(0, 0)); date = dateTime.toMSecsSinceEpoch(); break; case 1: //Week @@ -74,7 +74,7 @@ void ClearPrivateData::dialogAccepted() } QSqlQuery query; - query.exec("DELETE FROM history WHERE date > "+QString::number(date)); + query.exec("DELETE FROM history WHERE date > " + QString::number(date)); query.exec("VACUUM"); } if (ui->cookies->isChecked()) { diff --git a/src/other/clearprivatedata.h b/src/other/clearprivatedata.h index fcd41816d..c15ea7485 100644 --- a/src/other/clearprivatedata.h +++ b/src/other/clearprivatedata.h @@ -24,8 +24,9 @@ #include #include -namespace Ui { - class ClearPrivateData; +namespace Ui +{ +class ClearPrivateData; } class QupZilla; diff --git a/src/other/pagescreen.h b/src/other/pagescreen.h index c3f5dd9ba..fd9261fcb 100644 --- a/src/other/pagescreen.h +++ b/src/other/pagescreen.h @@ -24,8 +24,9 @@ #include #include -namespace Ui { - class PageScreen; +namespace Ui +{ +class PageScreen; } class WebView; @@ -43,7 +44,7 @@ private slots: private: void createPixmap(); - Ui::PageScreen *ui; + Ui::PageScreen* ui; WebView* m_view; QPixmap m_pagePixmap; }; diff --git a/src/other/sourceviewer.cpp b/src/other/sourceviewer.cpp index 40570be04..cbc1be320 100644 --- a/src/other/sourceviewer.cpp +++ b/src/other/sourceviewer.cpp @@ -24,10 +24,10 @@ SourceViewer::SourceViewer(QWebPage* page, const QString &selectedHtml) : QWidget(0) - ,m_page(page) + , m_page(page) { setAttribute(Qt::WA_DeleteOnClose); - setWindowTitle(tr("Source of ")+page->mainFrame()->url().toString()); + setWindowTitle(tr("Source of ") + page->mainFrame()->url().toString()); m_layout = new QBoxLayout(QBoxLayout::TopToBottom, this); m_sourceEdit = new QTextEdit(this); m_sourceEdit->setObjectName("sourceviewer-textedit"); @@ -89,15 +89,17 @@ SourceViewer::SourceViewer(QWebPage* page, const QString &selectedHtml) : qz_centerWidgetOnScreen(this); //Highlight selectedHtml - if (!selectedHtml.isEmpty()) + if (!selectedHtml.isEmpty()) { m_sourceEdit->find(selectedHtml, QTextDocument::FindWholeWords); + } } void SourceViewer::save() { - QString filePath = QFileDialog::getSaveFileName(this, tr("Save file..."), QDir::homePath()+"/source_code.html"); - if (filePath.isEmpty()) + QString filePath = QFileDialog::getSaveFileName(this, tr("Save file..."), QDir::homePath() + "/source_code.html"); + if (filePath.isEmpty()) { return; + } QFile file(filePath); if (!file.open(QFile::WriteOnly)) { @@ -114,7 +116,7 @@ void SourceViewer::save() void SourceViewer::findText() { if (m_layout->count() > 2) { - SourceViewerSearch* search = qobject_cast( m_layout->itemAt(1)->widget() ); + SourceViewerSearch* search = qobject_cast(m_layout->itemAt(1)->widget()); search->activateLineEdit(); return; } @@ -141,7 +143,7 @@ void SourceViewer::setTextEditable() void SourceViewer::setTextWordWrap() { - m_sourceEdit->setWordWrapMode( (m_sourceEdit->wordWrapMode()==QTextOption::NoWrap) ? QTextOption::WordWrap : QTextOption::NoWrap ); + m_sourceEdit->setWordWrapMode((m_sourceEdit->wordWrapMode() == QTextOption::NoWrap) ? QTextOption::WordWrap : QTextOption::NoWrap); m_statusBar->showMessage(tr("Word Wrap changed")); } @@ -149,12 +151,14 @@ void SourceViewer::setTextWordWrap() void SourceViewer::goToLine() { int line = QInputDialog::getInt(this, tr("Go to Line..."), tr("Enter line number"), 0, 1, 5000); - if (line == 0) + if (line == 0) { return; + } m_sourceEdit->setUpdatesEnabled(false); m_sourceEdit->moveCursor(QTextCursor::Start); - for (int i = 0; i < line; i++) + for (int i = 0; i < line; i++) { m_sourceEdit->moveCursor(QTextCursor::Down); + } m_sourceEdit->setUpdatesEnabled(true); } diff --git a/src/other/sourceviewersearch.cpp b/src/other/sourceviewersearch.cpp index a12ada9c3..c6768a051 100644 --- a/src/other/sourceviewersearch.cpp +++ b/src/other/sourceviewersearch.cpp @@ -51,8 +51,9 @@ void SourceViewerSearch::activateLineEdit() void SourceViewerSearch::next() { bool found = find(0); - if (!found) + if (!found) { m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start); + } ui->lineEdit->setProperty("notfound", !found); @@ -63,8 +64,9 @@ void SourceViewerSearch::next() void SourceViewerSearch::previous() { bool found = find(QTextDocument::FindBackward); - if (!found) + if (!found) { m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start); + } ui->lineEdit->setProperty("notfound", !found); @@ -75,8 +77,9 @@ void SourceViewerSearch::previous() bool SourceViewerSearch::find(QTextDocument::FindFlags flags) { QString string = ui->lineEdit->text(); - if (string.isEmpty()) + if (string.isEmpty()) { return true; + } if (string != m_lastSearchedString) { QTextCursor cursor = m_sourceViewer->sourceEdit()->textCursor(); cursor.setPosition(cursor.selectionStart()); @@ -87,8 +90,8 @@ bool SourceViewerSearch::find(QTextDocument::FindFlags flags) if (!m_sourceViewer->sourceEdit()->find(string, flags)) { QTextCursor cursor = m_sourceViewer->sourceEdit()->textCursor(); - m_sourceViewer->sourceEdit()->moveCursor( (flags == QTextDocument::FindBackward ) ? QTextCursor::End : QTextCursor::Start ); - if (!m_sourceViewer->sourceEdit()->find(string,flags)) { + m_sourceViewer->sourceEdit()->moveCursor((flags == QTextDocument::FindBackward) ? QTextCursor::End : QTextCursor::Start); + if (!m_sourceViewer->sourceEdit()->find(string, flags)) { cursor.clearSelection(); m_sourceViewer->sourceEdit()->setTextCursor(cursor); return false; diff --git a/src/other/sourceviewersearch.h b/src/other/sourceviewersearch.h index e41115551..aa3d7b592 100644 --- a/src/other/sourceviewersearch.h +++ b/src/other/sourceviewersearch.h @@ -23,8 +23,9 @@ #include "animatedwidget.h" -namespace Ui { - class SourceViewerSearch; +namespace Ui +{ +class SourceViewerSearch; } class SourceViewer; diff --git a/src/other/statusbarmessage.cpp b/src/other/statusbarmessage.cpp index 5efe42923..6fb078d96 100644 --- a/src/other/statusbarmessage.cpp +++ b/src/other/statusbarmessage.cpp @@ -89,8 +89,9 @@ StatusBarMessage::StatusBarMessage(QupZilla* mainClass) void StatusBarMessage::showMessage(const QString &message) { - if (p_QupZilla->statusBar()->isVisible()) + if (p_QupZilla->statusBar()->isVisible()) { p_QupZilla->statusBar()->showMessage(message); + } else { WebView* view = p_QupZilla->weView(); QWebFrame* mainFrame = view->page()->mainFrame(); @@ -99,10 +100,12 @@ void StatusBarMessage::showMessage(const QString &message) int verticalScrollSize = 0; const int scrollbarSize = p_QupZilla->style()->pixelMetric(QStyle::PM_ScrollBarExtent); - if (mainFrame->scrollBarMaximum(Qt::Horizontal)) + if (mainFrame->scrollBarMaximum(Qt::Horizontal)) { horizontalScrollSize = scrollbarSize; - if (mainFrame->scrollBarMaximum(Qt::Vertical)) + } + if (mainFrame->scrollBarMaximum(Qt::Vertical)) { verticalScrollSize = scrollbarSize; + } m_statusBarText->setText(message); m_statusBarText->resize(m_statusBarText->sizeHint()); @@ -113,8 +116,9 @@ void StatusBarMessage::showMessage(const QString &message) QRect statusRect = QRect(view->mapToGlobal(QPoint(0, position.y())), m_statusBarText->size()); - if (statusRect.contains(QCursor::pos())) + if (statusRect.contains(QCursor::pos())) { position.setY(position.y() - m_statusBarText->height()); + } m_statusBarText->move(view->mapToGlobal(position)); m_statusBarText->show(); @@ -123,8 +127,10 @@ void StatusBarMessage::showMessage(const QString &message) void StatusBarMessage::clearMessage() { - if (p_QupZilla->statusBar()->isVisible()) + if (p_QupZilla->statusBar()->isVisible()) { p_QupZilla->statusBar()->showMessage(""); - else + } + else { m_statusBarText->hide(); + } } diff --git a/src/other/statusbarmessage.h b/src/other/statusbarmessage.h index 40dcb1eef..5ddac3549 100644 --- a/src/other/statusbarmessage.h +++ b/src/other/statusbarmessage.h @@ -26,7 +26,8 @@ class QupZilla; class TipLabel; -class TipLabel : public SqueezeLabelV1 { +class TipLabel : public SqueezeLabelV1 +{ Q_OBJECT public: diff --git a/src/other/updater.cpp b/src/other/updater.cpp index 9cffba671..a6b06a335 100644 --- a/src/other/updater.cpp +++ b/src/other/updater.cpp @@ -23,9 +23,9 @@ Updater::Updater(QupZilla* mainClass, QObject* parent) : QObject(parent) - ,p_QupZilla(mainClass) + , p_QupZilla(mainClass) { - QTimer::singleShot(60*1000, this, SLOT(start()) ); //Start checking after 1 minute + QTimer::singleShot(60 * 1000, this, SLOT(start())); //Start checking after 1 minute } Updater::Version Updater::parseVersionFromString(const QString &string) @@ -34,16 +34,18 @@ Updater::Version Updater::parseVersionFromString(const QString &string) ver.isValid = false; QStringList v = string.split("."); - if (v.count() != 3) + if (v.count() != 3) { return ver; + } QStringList r = v.at(2).split("-"); ver.majorVersion = v.at(0).toInt(); ver.minorVersion = v.at(1).toInt(); ver.revisionNumber = r.at(0).toInt(); - if (r.count() == 2) + if (r.count() == 2) { ver.specialSymbol = r.at(1); + } ver.isValid = true; return ver; @@ -51,17 +53,21 @@ Updater::Version Updater::parseVersionFromString(const QString &string) bool Updater::isBiggerThan_SpecialSymbol(QString one, QString two) { - if (one.contains("rc") && two.contains("b")) + if (one.contains("rc") && two.contains("b")) { return true; + } - if (one.contains("b") && two.contains("rc")) + if (one.contains("b") && two.contains("rc")) { return false; + } - if (one.isEmpty()) + if (one.isEmpty()) { return true; + } - if (two.isEmpty()) + if (two.isEmpty()) { return false; + } if (one.contains("b")) { int o = one.remove("b").toInt(); @@ -96,7 +102,7 @@ void Updater::startDownloadingUpdateInfo(const QUrl &url) void Updater::downCompleted(QNetworkReply* reply) { QString html = QString(reply->readAll()); - if (html.startsWith("Version:")){ + if (html.startsWith("Version:")) { html.remove("Version:"); Version current = parseVersionFromString(QupZilla::VERSION); Version updated = parseVersionFromString(html); diff --git a/src/other/updater.h b/src/other/updater.h index 53a9b8137..377f2e465 100644 --- a/src/other/updater.h +++ b/src/other/updater.h @@ -38,8 +38,7 @@ public: int revisionNumber; QString specialSymbol; - bool operator<(const Version &other) const - { + bool operator<(const Version &other) const { if (!this->isValid || !other.isValid) return false; if (this->majorVersion < other.majorVersion) @@ -54,13 +53,11 @@ public: return false; } - bool operator>(const Version &other) const - { + bool operator>(const Version &other) const { return !operator<(other); } - bool operator==(const Version &other) const - { + bool operator==(const Version &other) const { if (!this->isValid || !other.isValid) return false; @@ -70,15 +67,13 @@ public: this->specialSymbol == other.specialSymbol); } - bool operator>=(const Version &other) const - { + bool operator>=(const Version &other) const { if (*this == other) return true; return *this > other; } - bool operator<=(const Version &other) const - { + bool operator<=(const Version &other) const { if (*this == other) return true; return *this < other; diff --git a/src/plugins/clicktoflash.cpp b/src/plugins/clicktoflash.cpp index 716be654d..b2f05068e 100644 --- a/src/plugins/clicktoflash.cpp +++ b/src/plugins/clicktoflash.cpp @@ -50,15 +50,15 @@ #include "qupzilla.h" ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNames, const QStringList &argumentValues, WebPage* parentPage) - : QWidget() - , m_argumentNames(argumentNames) - , m_argumentValues(argumentValues) - , m_toolButton(0) - , m_layout1(0) - , m_layout2(0) - , m_frame(0) - , m_url(pluginUrl) - , m_page(parentPage) + : QWidget() + , m_argumentNames(argumentNames) + , m_argumentValues(argumentValues) + , m_toolButton(0) + , m_layout1(0) + , m_layout2(0) + , m_frame(0) + , m_url(pluginUrl) + , m_page(parentPage) { //AdBlock AdBlockManager* manager = AdBlockManager::instance(); @@ -74,7 +74,7 @@ ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNam m_layout1 = new QHBoxLayout(this); m_frame = new QFrame(this); m_frame->setObjectName("click2flash-frame"); - m_frame->setContentsMargins(0,0,0,0); + m_frame->setContentsMargins(0, 0, 0, 0); m_layout2 = new QHBoxLayout(m_frame); m_toolButton = new QToolButton(this); m_toolButton->setObjectName("click2flash-toolbutton"); @@ -83,11 +83,11 @@ ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNam m_toolButton->setCursor(Qt::PointingHandCursor); m_layout2->addWidget(m_toolButton); m_layout1->addWidget(m_frame); - m_layout1->setContentsMargins(0,0,0,0); - m_layout2->setContentsMargins(0,0,0,0); + m_layout1->setContentsMargins(0, 0, 0, 0); + m_layout2->setContentsMargins(0, 0, 0, 0); connect(m_toolButton, SIGNAL(clicked()), this, SLOT(load())); - setMinimumSize(27,27); + setMinimumSize(27, 27); setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); @@ -129,8 +129,9 @@ void ClickToFlash::toWhitelist() void ClickToFlash::hideAdBlocked() { findElement(); - if (!m_element.isNull()) + if (!m_element.isNull()) { m_element.setAttribute("style", "display:none;"); + } else { hide(); } @@ -140,8 +141,9 @@ void ClickToFlash::hideAdBlocked() void ClickToFlash::findElement() { - if (!m_toolButton) + if (!m_toolButton) { return; + } QWidget* parent = parentWidget(); QWebView* view = 0; @@ -152,8 +154,9 @@ void ClickToFlash::findElement() } parent = parent->parentWidget(); } - if (!view) + if (!view) { return; + } QList frames; frames.append(view->page()->frameAt(view->mapFromGlobal(m_toolButton->mapToGlobal(m_toolButton->pos())))); @@ -162,8 +165,9 @@ void ClickToFlash::findElement() while (!frames.isEmpty()) { QWebFrame* frame = frames.takeFirst(); - if (!frame) + if (!frame) { continue; + } QWebElement docElement = frame->documentElement(); QWebElementCollection elements; @@ -171,9 +175,10 @@ void ClickToFlash::findElement() elements.append(docElement.findAll(QLatin1String("object"))); QWebElement element; - foreach (element, elements) { - if (!checkElement(element) && !checkUrlOnElement(element)) + foreach(element, elements) { + if (!checkElement(element) && !checkUrlOnElement(element)) { continue; + } m_element = element; return; } @@ -186,7 +191,8 @@ void ClickToFlash::load() findElement(); if (m_element.isNull()) { qWarning("Click2Flash: Cannot find Flash object."); - } else { + } + else { QWebElement substitute = m_element.clone(); substitute.setAttribute(QLatin1String("type"), "application/futuresplash"); m_element.replace(substitute); @@ -196,10 +202,12 @@ void ClickToFlash::load() bool ClickToFlash::checkUrlOnElement(QWebElement el) { QString checkString = el.attribute("src"); - if (checkString.isEmpty()) + if (checkString.isEmpty()) { checkString = el.attribute("data"); - if (checkString.isEmpty()) + } + if (checkString.isEmpty()) { checkString = el.attribute("value"); + } checkString = m_page->getView()->url().resolved(QUrl(checkString)).toString(QUrl::RemoveQuery); @@ -209,9 +217,10 @@ bool ClickToFlash::checkUrlOnElement(QWebElement el) bool ClickToFlash::checkElement(QWebElement el) { if (m_argumentNames == el.attributeNames()) { - foreach (QString name, m_argumentNames) { - if (m_argumentValues.indexOf(el.attribute(name)) == -1) + foreach(QString name, m_argumentNames) { + if (m_argumentValues.indexOf(el.attribute(name)) == -1) { return false; + } } return true; } @@ -228,15 +237,16 @@ void ClickToFlash::showInfo() lay->addRow(new QLabel(tr("Attribute Name")), new QLabel(tr("Value"))); int i = 0; - foreach (QString name, m_argumentNames) { + foreach(QString name, m_argumentNames) { QString value = m_argumentValues.at(i); lay->addRow(new SqueezeLabelV2(name), new SqueezeLabelV2(value)); i++; } - if (i == 0) + if (i == 0) { lay->addRow(new QLabel(tr("No more informations available."))); + } widg->setMaximumHeight(500); qz_centerWidgetToParent(widg, m_page->qupzilla()); @@ -245,12 +255,16 @@ void ClickToFlash::showInfo() ClickToFlash::~ClickToFlash() { - if (m_toolButton) + if (m_toolButton) { delete m_toolButton; - if (m_layout1) + } + if (m_layout1) { delete m_layout1; - if (m_layout2) + } + if (m_layout2) { delete m_layout2; - if (m_frame) + } + if (m_frame) { delete m_frame; + } } diff --git a/src/plugins/plugininterface.h b/src/plugins/plugininterface.h index c217d455a..e2862e69a 100644 --- a/src/plugins/plugininterface.h +++ b/src/plugins/plugininterface.h @@ -57,7 +57,7 @@ public: { Q_UNUSED(op) Q_UNUSED(request) Q_UNUSED(outgoingData) return 0; } }; - Q_DECLARE_INTERFACE(PluginInterface, "Qupzilla.Browser.PluginInterface/1.0") +Q_DECLARE_INTERFACE(PluginInterface, "Qupzilla.Browser.PluginInterface/1.0") #endif // PLUGININTERFACE_H diff --git a/src/plugins/pluginproxy.cpp b/src/plugins/pluginproxy.cpp index 8b398a70b..0cb9faaaa 100644 --- a/src/plugins/pluginproxy.cpp +++ b/src/plugins/pluginproxy.cpp @@ -27,61 +27,68 @@ PluginProxy::PluginProxy() : void PluginProxy::populateWebViewMenu(QMenu* menu, QWebView* view, QWebHitTestResult r) { - if (!menu || !view || loadedPlugins.count() == 0) + if (!menu || !view || loadedPlugins.count() == 0) { return; + } menu->addSeparator(); int count = menu->actions().count(); - foreach(PluginInterface* iPlugin, loadedPlugins) - iPlugin->populateWebViewMenu(menu, view, r); + foreach(PluginInterface * iPlugin, loadedPlugins) + iPlugin->populateWebViewMenu(menu, view, r); - if (menu->actions().count() == count) - menu->removeAction(menu->actions().at(count-1)); + if (menu->actions().count() == count) { + menu->removeAction(menu->actions().at(count - 1)); + } } void PluginProxy::populateToolsMenu(QMenu* menu) { - if (!menu || loadedPlugins.count() == 0) + if (!menu || loadedPlugins.count() == 0) { return; + } int count = menu->actions().count(); - foreach(PluginInterface* iPlugin, loadedPlugins) - iPlugin->populateToolsMenu(menu); + foreach(PluginInterface * iPlugin, loadedPlugins) + iPlugin->populateToolsMenu(menu); - if (menu->actions().count() != count) + if (menu->actions().count() != count) { menu->addSeparator(); + } } void PluginProxy::populateHelpMenu(QMenu* menu) { - if (!menu || loadedPlugins.count() == 0) + if (!menu || loadedPlugins.count() == 0) { return; + } int count = menu->actions().count(); - foreach(PluginInterface* iPlugin, loadedPlugins) - iPlugin->populateHelpMenu(menu); + foreach(PluginInterface * iPlugin, loadedPlugins) + iPlugin->populateHelpMenu(menu); - if (menu->actions().count() != count) + if (menu->actions().count() != count) { menu->addSeparator(); + } } -QNetworkReply* PluginProxy::createNetworkRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData) +QNetworkReply* PluginProxy::createNetworkRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData) { QNetworkReply* reply = 0; - foreach(PluginInterface* iPlugin, loadedPlugins) { + foreach(PluginInterface * iPlugin, loadedPlugins) { reply = iPlugin->createNetworkRequest(op, request, outgoingData); - if (reply) + if (reply) { break; + } } return reply; } void PluginProxy::c2f_loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("ClickToFlash"); c2f_whitelist = settings.value("whitelist", QStringList()).toStringList(); c2f_enabled = settings.value("Enabled", false).toBool(); @@ -90,7 +97,7 @@ void PluginProxy::c2f_loadSettings() void PluginProxy::c2f_saveSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("ClickToFlash"); settings.setValue("whitelist", c2f_whitelist); settings.setValue("Enabled", c2f_enabled); diff --git a/src/plugins/plugins.cpp b/src/plugins/plugins.cpp index 4aeb2b093..6597f6fdb 100644 --- a/src/plugins/plugins.cpp +++ b/src/plugins/plugins.cpp @@ -29,7 +29,7 @@ void Plugins::loadSettings() { m_allowedPluginFileNames.clear(); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Plugin-Settings"); m_pluginsEnabled = settings.value("EnablePlugins", true).toBool(); m_allowedPluginFileNames = settings.value("AllowedPlugins", QStringList()).toStringList(); @@ -38,25 +38,27 @@ void Plugins::loadSettings() void Plugins::loadPlugins() { - if (!m_pluginsEnabled) + if (!m_pluginsEnabled) { return; + } m_availablePluginFileNames.clear(); loadedPlugins.clear(); QDir pluginsDir = QDir(mApp->PLUGINSDIR); - foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + foreach(QString fileName, pluginsDir.entryList(QDir::Files)) { m_availablePluginFileNames.append(fileName); - if (!m_allowedPluginFileNames.contains(fileName)) + if (!m_allowedPluginFileNames.contains(fileName)) { continue; + } QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); QObject* plugin = loader.instance(); if (plugin) { PluginInterface* iPlugin = qobject_cast(plugin); - iPlugin->init(mApp->getActiveProfilPath()+"plugins.ini"); + iPlugin->init(mApp->getActiveProfilPath() + "plugins.ini"); if (!iPlugin->testPlugin()) { loader.unload(); continue; @@ -74,14 +76,17 @@ void Plugins::loadPlugins() PluginInterface* Plugins::getPlugin(QString pluginFileName) { QString path = mApp->PLUGINSDIR + pluginFileName; - if (!QFile::exists(path)) + if (!QFile::exists(path)) { return 0; + } QPluginLoader loader(path); QObject* plugin = loader.instance(); if (plugin) { PluginInterface* iPlugin = qobject_cast(plugin); return iPlugin; - } else + } + else { return 0; + } } diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index af5003f5e..0a6adde70 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -34,7 +34,7 @@ public: explicit Plugins(QObject* parent = 0); QStringList getAvailablePlugins() { return m_availablePluginFileNames; } - QStringList getAllowedPlugins () { return m_allowedPluginFileNames; } + QStringList getAllowedPlugins() { return m_allowedPluginFileNames; } PluginInterface* getPlugin(QString pluginFileName); //void setPluginsAllowed(bool state) { pluginsEnabled = state; qDebug() << state;} diff --git a/src/plugins/webpluginfactory.cpp b/src/plugins/webpluginfactory.cpp index 4acfc02b7..b0aac075e 100644 --- a/src/plugins/webpluginfactory.cpp +++ b/src/plugins/webpluginfactory.cpp @@ -30,30 +30,36 @@ WebPluginFactory::WebPluginFactory(QObject* parent) QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const { QString mime = mimeType.trimmed(); //Fixing bad behaviour when mimeType contains spaces - if (mime.isEmpty()) - return 0; - - if (mime != "application/x-shockwave-flash") { - if (mime != "application/futuresplash") - qDebug() << "missing mimeType handler for: " << mime; + if (mime.isEmpty()) { return 0; } - if (!mApp->plugins()->c2f_isEnabled()) + if (mime != "application/x-shockwave-flash") { + if (mime != "application/futuresplash") { + qDebug() << "missing mimeType handler for: " << mime; + } return 0; + } + + if (!mApp->plugins()->c2f_isEnabled()) { + return 0; + } //Click2Flash whitelist QStringList whitelist = mApp->plugins()->c2f_getWhiteList(); - if (whitelist.contains(url.host()) || whitelist.contains("www."+url.host()) || whitelist.contains(url.host().remove("www."))) + if (whitelist.contains(url.host()) || whitelist.contains("www." + url.host()) || whitelist.contains(url.host().remove("www."))) { return 0; + } WebPluginFactory* factory = const_cast(this); - if (!factory) + if (!factory) { return 0; + } WebPage* page = factory->parentPage(); - if (!page) + if (!page) { return 0; + } ClickToFlash* ctf = new ClickToFlash(url, argumentNames, argumentValues, page); @@ -62,8 +68,9 @@ QObject* WebPluginFactory::create(const QString &mimeType, const QUrl &url, cons WebPage* WebPluginFactory::parentPage() { - if (m_page) + if (m_page) { return m_page; + } WebPage* page = qobject_cast (parent()); return page; diff --git a/src/plugins/webpluginfactory.h b/src/plugins/webpluginfactory.h index 0564276f6..311ced40c 100644 --- a/src/plugins/webpluginfactory.h +++ b/src/plugins/webpluginfactory.h @@ -28,7 +28,7 @@ class WebPluginFactory : public QWebPluginFactory public: WebPluginFactory(QObject* parent); - virtual QObject* create (const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const; + virtual QObject* create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const; QList plugins() const; private: diff --git a/src/preferences/acceptlanguage.cpp b/src/preferences/acceptlanguage.cpp index d3c70241f..ea3f27f3d 100644 --- a/src/preferences/acceptlanguage.cpp +++ b/src/preferences/acceptlanguage.cpp @@ -46,8 +46,9 @@ QStringList AcceptLanguage::defaultLanguage() QByteArray AcceptLanguage::generateHeader(const QStringList &langs) { - if (langs.count() == 0) + if (langs.count() == 0) { return QByteArray(); + } QByteArray header; header.append(langs.at(0)); @@ -56,8 +57,9 @@ QByteArray AcceptLanguage::generateHeader(const QStringList &langs) for (int i = 1; i < langs.count(); i++) { QString s = ", " + langs.at(i) + ";q=0,"; s.append(QString::number(counter)); - if (counter != 2) - counter-=2; + if (counter != 2) { + counter -= 2; + } header.append(s); } @@ -72,19 +74,21 @@ AcceptLanguage::AcceptLanguage(QWidget* parent) { ui->setupUi(this); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Language"); QStringList langs = settings.value("acceptLanguage", defaultLanguage()).toStringList(); - foreach (QString code, langs) { + foreach(QString code, langs) { QString code_ = code; QLocale loc = QLocale(code_.replace("-", "_")); QString label; - if (loc.language() == QLocale::C) + if (loc.language() == QLocale::C) { label = tr("Personal [%1]").arg(code); - else + } + else { label = QString("%1/%2 [%3]").arg(loc.languageToString(loc.language()), loc.countryToString(loc.country()), code); + } ui->listWidget->addItem(label); } @@ -103,17 +107,19 @@ QStringList AcceptLanguage::expand(const QLocale::Language &language) QString languageString; if (countries.count() == 1) { languageString = QString(QLatin1String("%1 [%2]")) - .arg(QLocale::languageToString(language)) - .arg(QLocale(language).name().split(QLatin1Char('_')).at(0)); - } else { + .arg(QLocale::languageToString(language)) + .arg(QLocale(language).name().split(QLatin1Char('_')).at(0)); + } + else { languageString = QString(QLatin1String("%1/%2 [%3]")) - .arg(QLocale::languageToString(language)) - .arg(QLocale::countryToString(countries.at(j))) - .arg(QLocale(language, countries.at(j)).name().split(QLatin1Char('_')).join(QLatin1String("-")).toLower()); + .arg(QLocale::languageToString(language)) + .arg(QLocale::countryToString(countries.at(j))) + .arg(QLocale(language, countries.at(j)).name().split(QLatin1Char('_')).join(QLatin1String("-")).toLower()); } - if (!allLanguages.contains(languageString)) + if (!allLanguages.contains(languageString)) { allLanguages.append(languageString); + } } return allLanguages; } @@ -125,23 +131,27 @@ void AcceptLanguage::addLanguage() _ui.setupUi(&dialog); QStringList allLanguages; - for (int i = 1 + (int)QLocale::C; i <= (int)QLocale::LastLanguage; ++i) + for (int i = 1 + (int)QLocale::C; i <= (int)QLocale::LastLanguage; ++i) { allLanguages += expand(QLocale::Language(i)); + } _ui.listWidget->addItems(allLanguages); connect(_ui.listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), &dialog, SLOT(accept())); - if (dialog.exec() == QDialog::Rejected) + if (dialog.exec() == QDialog::Rejected) { return; + } if (!_ui.ownDefinition->text().isEmpty()) { QString title = tr("Personal [%1]").arg(_ui.ownDefinition->text()); ui->listWidget->addItem(title); - } else { + } + else { QListWidgetItem* c = _ui.listWidget->currentItem(); - if (!c) + if (!c) { return; + } ui->listWidget->addItem(c->text()); } @@ -151,8 +161,9 @@ void AcceptLanguage::addLanguage() void AcceptLanguage::removeLanguage() { QListWidgetItem* currentItem = ui->listWidget->currentItem(); - if (currentItem) + if (currentItem) { delete currentItem; + } } void AcceptLanguage::upLanguage() @@ -160,8 +171,9 @@ void AcceptLanguage::upLanguage() int index = ui->listWidget->currentRow(); QListWidgetItem* currentItem = ui->listWidget->currentItem(); - if (!currentItem || index == 0) + if (!currentItem || index == 0) { return; + } ui->listWidget->takeItem(index); ui->listWidget->insertItem(index - 1, currentItem); @@ -173,8 +185,9 @@ void AcceptLanguage::downLanguage() int index = ui->listWidget->currentRow(); QListWidgetItem* currentItem = ui->listWidget->currentItem(); - if (!currentItem || index == ui->listWidget->count() - 1) + if (!currentItem || index == ui->listWidget->count() - 1) { return; + } ui->listWidget->takeItem(index); ui->listWidget->insertItem(index + 1, currentItem); @@ -191,7 +204,7 @@ void AcceptLanguage::accept() langs.append(code); } - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Language"); settings.setValue("acceptLanguage", langs); diff --git a/src/preferences/acceptlanguage.h b/src/preferences/acceptlanguage.h index 122b212d0..842bf7832 100644 --- a/src/preferences/acceptlanguage.h +++ b/src/preferences/acceptlanguage.h @@ -22,8 +22,9 @@ #include #include -namespace Ui { - class AcceptLanguage; +namespace Ui +{ +class AcceptLanguage; } class AcceptLanguage : public QDialog diff --git a/src/preferences/autofillmanager.cpp b/src/preferences/autofillmanager.cpp index acce46f1f..81f453b59 100644 --- a/src/preferences/autofillmanager.cpp +++ b/src/preferences/autofillmanager.cpp @@ -41,7 +41,7 @@ void AutoFillManager::loadPasswords() QSqlQuery query; query.exec("SELECT server, password, id FROM autofill"); ui->treePass->clear(); - while(query.next()) { + while (query.next()) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->treePass); item->setText(0, query.value(0).toString()); // item->setText(1, query.value(1).toString()); @@ -53,7 +53,7 @@ void AutoFillManager::loadPasswords() query.exec("SELECT server, id FROM autofill_exceptions"); ui->treeExcept->clear(); - while(query.next()) { + while (query.next()) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeExcept); item->setText(0, query.value(0).toString()); item->setWhatsThis(0, query.value(1).toString()); @@ -63,19 +63,22 @@ void AutoFillManager::loadPasswords() void AutoFillManager::showPasswords() { - if (m_passwordsShown) + if (m_passwordsShown) { return; + } m_passwordsShown = true; int result = QMessageBox::question(this, tr("Show Passwords"), tr("Are you sure that you want to show all passwords?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - if (result != QMessageBox::Yes) + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (result != QMessageBox::Yes) { return; + } for (int i = 0; i < ui->treePass->topLevelItemCount(); i++) { QTreeWidgetItem* item = ui->treePass->topLevelItem(i); - if (!item) + if (!item) { continue; + } item->setText(1, item->whatsThis(1)); } @@ -86,11 +89,12 @@ void AutoFillManager::showPasswords() void AutoFillManager::removePass() { QTreeWidgetItem* curItem = ui->treePass->currentItem(); - if (!curItem) + if (!curItem) { return; + } QString id = curItem->whatsThis(0); QSqlQuery query; - query.exec("DELETE FROM autofill WHERE id="+id); + query.exec("DELETE FROM autofill WHERE id=" + id); delete curItem; } @@ -98,9 +102,10 @@ void AutoFillManager::removePass() void AutoFillManager::removeAllPass() { QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"), - tr("Are you sure to delete all passwords on your computer?"), QMessageBox::Yes | QMessageBox::No); - if (button != QMessageBox::Yes) + tr("Are you sure to delete all passwords on your computer?"), QMessageBox::Yes | QMessageBox::No); + if (button != QMessageBox::Yes) { return; + } QSqlQuery query; query.exec("DELETE FROM autofill"); @@ -111,8 +116,9 @@ void AutoFillManager::removeAllPass() void AutoFillManager::editPass() { QTreeWidgetItem* curItem = ui->treePass->currentItem(); - if (!curItem) + if (!curItem) { return; + } bool ok; QString text = QInputDialog::getText(this, tr("Edit password"), tr("Change password:"), QLineEdit::Normal, curItem->whatsThis(1), &ok); @@ -133,8 +139,9 @@ void AutoFillManager::editPass() query.bindValue(2, curItem->whatsThis(0)); query.exec(); - if (m_passwordsShown) + if (m_passwordsShown) { curItem->setText(1, text); + } curItem->setWhatsThis(1, text); } } @@ -142,11 +149,12 @@ void AutoFillManager::editPass() void AutoFillManager::removeExcept() { QTreeWidgetItem* curItem = ui->treeExcept->currentItem(); - if (!curItem) + if (!curItem) { return; + } QString id = curItem->whatsThis(0); QSqlQuery query; - query.exec("DELETE FROM autofill_exceptions WHERE id="+id); + query.exec("DELETE FROM autofill_exceptions WHERE id=" + id); delete curItem; } diff --git a/src/preferences/autofillmanager.h b/src/preferences/autofillmanager.h index 025b26599..0b435a8d5 100644 --- a/src/preferences/autofillmanager.h +++ b/src/preferences/autofillmanager.h @@ -27,8 +27,9 @@ #include #include -namespace Ui { - class AutoFillManager; +namespace Ui +{ +class AutoFillManager; } class AutoFillManager : public QWidget diff --git a/src/preferences/pluginslist.cpp b/src/preferences/pluginslist.cpp index 60df5e422..de6e6fe7b 100644 --- a/src/preferences/pluginslist.cpp +++ b/src/preferences/pluginslist.cpp @@ -30,13 +30,13 @@ PluginsList::PluginsList(QWidget* parent) : //Application Extensions refresh(); connect(ui->butSettings, SIGNAL(clicked()), this, SLOT(settingsClicked())); - connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*))); + connect(ui->list, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged(QListWidgetItem*))); connect(ui->butLoad, SIGNAL(clicked()), this, SLOT(reloadPlugins())); connect(ui->allowAppPlugins, SIGNAL(clicked(bool)), this, SLOT(allowAppPluginsChanged(bool))); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Plugin-Settings"); - ui->allowAppPlugins->setChecked( settings.value("EnablePlugins",true).toBool() ); + ui->allowAppPlugins->setChecked(settings.value("EnablePlugins", true).toBool()); settings.endGroup(); allowAppPluginsChanged(ui->allowAppPlugins->isChecked()); @@ -47,9 +47,9 @@ PluginsList::PluginsList(QWidget* parent) : settings.beginGroup("ClickToFlash"); QStringList whitelist = mApp->plugins()->c2f_getWhiteList(); - ui->allowClick2Flash->setChecked( settings.value("Enable",true).toBool() ); + ui->allowClick2Flash->setChecked(settings.value("Enable", true).toBool()); settings.endGroup(); - foreach (QString site, whitelist) { + foreach(QString site, whitelist) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->whitelist); item->setText(0, site); } @@ -59,8 +59,9 @@ PluginsList::PluginsList(QWidget* parent) : void PluginsList::addWhitelist() { QString site = QInputDialog::getText(this, tr("Add site to whitelist"), tr("Server without http:// (ex. youtube.com)")); - if (site.isEmpty()) + if (site.isEmpty()) { return; + } mApp->plugins()->c2f_addWhitelist(site); ui->whitelist->insertTopLevelItem(0, new QTreeWidgetItem(QStringList(site))); @@ -69,8 +70,9 @@ void PluginsList::addWhitelist() void PluginsList::removeWhitelist() { QTreeWidgetItem* item = ui->whitelist->currentItem(); - if (!item) + if (!item) { return; + } mApp->plugins()->c2f_removeWhitelist(item->text(0)); delete item; @@ -78,9 +80,9 @@ void PluginsList::removeWhitelist() void PluginsList::save() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Plugin-Settings"); - settings.setValue("EnablePlugins",ui->allowAppPlugins->isChecked()); + settings.setValue("EnablePlugins", ui->allowAppPlugins->isChecked()); settings.endGroup(); reloadPlugins(); @@ -88,7 +90,7 @@ void PluginsList::save() void PluginsList::allowAppPluginsChanged(bool state) { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Plugin-Settings"); settings.setValue("EnablePlugins", state); settings.endGroup(); @@ -98,7 +100,7 @@ void PluginsList::allowAppPluginsChanged(bool state) void PluginsList::allowC2FChanged(bool state) { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("ClickToFlash"); settings.setValue("Enable", state); settings.endGroup(); @@ -117,22 +119,24 @@ void PluginsList::refresh() QStringList availablePlugins = mApp->plugins()->getAvailablePlugins(); QStringList allowedPlugins = mApp->plugins()->getAllowedPlugins(); - foreach (QString fileName, availablePlugins) { + foreach(QString fileName, availablePlugins) { PluginInterface* plugin = mApp->plugins()->getPlugin(fileName); - if (!plugin) + if (!plugin) { continue; + } QListWidgetItem* item = new QListWidgetItem(ui->list); - item->setText(""+plugin->pluginName()+" ("+plugin->pluginVersion()+") by "+plugin->pluginAuthor()+"\n" - +plugin->pluginInfo()+"\n"+plugin->pluginDescription() ); + item->setText("" + plugin->pluginName() + " (" + plugin->pluginVersion() + ") by " + plugin->pluginAuthor() + "\n" + + plugin->pluginInfo() + "\n" + plugin->pluginDescription()); QIcon icon = plugin->pluginIcon(); - if (icon.isNull()) + if (icon.isNull()) { icon = QIcon(":/icons/preferences/extension.png"); + } item->setIcon(icon); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState( (allowedPlugins.contains(fileName) ) ? Qt::Checked : Qt::Unchecked); + item->setCheckState((allowedPlugins.contains(fileName)) ? Qt::Checked : Qt::Unchecked); item->setWhatsThis(plugin->hasSettings() ? "1" : "0"); item->setToolTip(fileName); @@ -142,26 +146,31 @@ void PluginsList::refresh() void PluginsList::currentChanged(QListWidgetItem* item) { - if (!item) + if (!item) { return; + } QString has = item->whatsThis(); bool show; - if (has == "1") + if (has == "1") { show = true; - else + } + else { show = false; + } - if(item->checkState() == Qt::Unchecked) + if (item->checkState() == Qt::Unchecked) { show = false; + } ui->butSettings->setEnabled(show); } void PluginsList::settingsClicked() { - if (!ui->list->currentItem()) + if (!ui->list->currentItem()) { return; + } QString name = ui->list->currentItem()->toolTip(); PluginInterface* plugin = mApp->plugins()->getPlugin(name); @@ -172,12 +181,13 @@ void PluginsList::reloadPlugins() { QStringList allowedPlugins; for (int i = 0; i < ui->list->count(); i++) { - if (ui->list->item(i)->checkState() == Qt::Checked) + if (ui->list->item(i)->checkState() == Qt::Checked) { allowedPlugins.append(ui->list->item(i)->toolTip()); + } } - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Plugin-Settings"); - settings.setValue("AllowedPlugins",allowedPlugins); + settings.setValue("AllowedPlugins", allowedPlugins); settings.endGroup(); mApp->plugins()->loadSettings(); diff --git a/src/preferences/pluginslist.h b/src/preferences/pluginslist.h index 5efdc43ed..7220f6067 100644 --- a/src/preferences/pluginslist.h +++ b/src/preferences/pluginslist.h @@ -22,8 +22,9 @@ #include #include -namespace Ui { - class PluginsList; +namespace Ui +{ +class PluginsList; } class PluginsList : public QWidget diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 3472cc29c..2a195615d 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -43,25 +43,28 @@ bool removeFile(const QString &fullFileName) { QFile f(fullFileName); - if (f.exists()) + if (f.exists()) { return f.remove(); - else return false; + } + else { + return false; + } } void removeDir(const QString &d) { QDir dir(d); - if (dir.exists()) - { + if (dir.exists()) { const QFileInfoList list = dir.entryInfoList(); QFileInfo fi; - for (int l = 0; l < list.size(); l++) - { + for (int l = 0; l < list.size(); l++) { fi = list.at(l); - if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..") + if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..") { removeDir(fi.absoluteFilePath()); - else if (fi.isFile()) + } + else if (fi.isFile()) { removeFile(fi.absoluteFilePath()); + } } dir.rmdir(d); @@ -77,24 +80,26 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); //GENERAL URLs settings.beginGroup("Web-URL-Settings"); - m_homepage = settings.value("homepage","qupzilla:start").toString(); - m_newTabUrl = settings.value("newTabUrl","").toString(); + m_homepage = settings.value("homepage", "qupzilla:start").toString(); + m_newTabUrl = settings.value("newTabUrl", "").toString(); ui->homepage->setText(m_homepage); ui->newTabUrl->setText(m_newTabUrl); - int afterLaunch = settings.value("afterLaunch",1).toInt(); + int afterLaunch = settings.value("afterLaunch", 1).toInt(); settings.endGroup(); ui->afterLaunch->setCurrentIndex(afterLaunch); - ui->checkUpdates->setChecked( settings.value("Web-Browser-Settings/CheckUpdates", true).toBool() ); + ui->checkUpdates->setChecked(settings.value("Web-Browser-Settings/CheckUpdates", true).toBool()); ui->newTabFrame->setVisible(false); - if (m_newTabUrl.isEmpty()) + if (m_newTabUrl.isEmpty()) { ui->newTab->setCurrentIndex(0); - else if (m_newTabUrl == m_homepage) + } + else if (m_newTabUrl == m_homepage) { ui->newTab->setCurrentIndex(1); - else{ + } + else { ui->newTab->setCurrentIndex(2); ui->newTabFrame->setVisible(true); } @@ -111,9 +116,10 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) ui->startProfile->addItem(m_actProfileName); QDir profilesDir(QDir::homePath() + "/.qupzilla/profiles/"); QStringList list_ = profilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); - foreach (QString name, list_) { - if (m_actProfileName == name) + foreach(QString name, list_) { + if (m_actProfileName == name) { continue; + } ui->startProfile->addItem(name); } connect(ui->createProfile, SIGNAL(clicked()), this, SLOT(createProfile())); @@ -123,13 +129,13 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) //APPEREANCE m_themesManager = new ThemeManager(ui->themesWidget); settings.beginGroup("Browser-View-Settings"); - ui->showStatusbar->setChecked( settings.value("showStatusBar",true).toBool() ); - ui->showBookmarksToolbar->setChecked( p_QupZilla->bookmarksToolbar()->isVisible() ); - ui->showNavigationToolbar->setChecked( p_QupZilla->navigationBar()->isVisible() ); - ui->showHome->setChecked( settings.value("showHomeButton",true).toBool() ); - ui->showBackForward->setChecked( settings.value("showBackForwardButtons",true).toBool() ); - ui->showAddTabButton->setChecked( settings.value("showAddTabButton", false).toBool() ); - ui->useTransparentBg->setChecked( settings.value("useTransparentBackground",false).toBool() ); + ui->showStatusbar->setChecked(settings.value("showStatusBar", true).toBool()); + ui->showBookmarksToolbar->setChecked(p_QupZilla->bookmarksToolbar()->isVisible()); + ui->showNavigationToolbar->setChecked(p_QupZilla->navigationBar()->isVisible()); + ui->showHome->setChecked(settings.value("showHomeButton", true).toBool()); + ui->showBackForward->setChecked(settings.value("showBackForwardButtons", true).toBool()); + ui->showAddTabButton->setChecked(settings.value("showAddTabButton", false).toBool()); + ui->useTransparentBg->setChecked(settings.value("useTransparentBackground", false).toBool()); settings.endGroup(); #ifdef Q_WS_WIN ui->useTransparentBg->setEnabled(QtWin::isCompositionEnabled()); @@ -137,48 +143,49 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) //TABS settings.beginGroup("Browser-Tabs-Settings"); - ui->makeMovable->setChecked( settings.value("makeTabsMovable",true).toBool() ); - ui->hideCloseOnTab->setChecked( settings.value("hideCloseButtonWithOneTab",false).toBool() ); - ui->hideTabsOnTab->setChecked( settings.value("hideTabsWithOneTab",false).toBool() ); - ui->activateLastTab->setChecked( settings.value("ActivateLastTabWhenClosingActual", false).toBool() ); - ui->askWhenClosingMultipleTabs->setChecked( settings.value("AskOnClosing", false).toBool() ); + ui->makeMovable->setChecked(settings.value("makeTabsMovable", true).toBool()); + ui->hideCloseOnTab->setChecked(settings.value("hideCloseButtonWithOneTab", false).toBool()); + ui->hideTabsOnTab->setChecked(settings.value("hideTabsWithOneTab", false).toBool()); + ui->activateLastTab->setChecked(settings.value("ActivateLastTabWhenClosingActual", false).toBool()); + ui->askWhenClosingMultipleTabs->setChecked(settings.value("AskOnClosing", false).toBool()); settings.endGroup(); //AddressBar settings.beginGroup("AddressBar"); - ui->selectAllOnFocus->setChecked( settings.value("SelectAllTextOnDoubleClick", true).toBool() ); - ui->addComWithCtrl->setChecked( settings.value("AddComDomainWithCtrlKey", false).toBool() ); - ui->addCountryWithAlt->setChecked( settings.value("AddCountryDomainWithAltKey", true).toBool() ); + ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool()); + ui->addComWithCtrl->setChecked(settings.value("AddComDomainWithCtrlKey", false).toBool()); + ui->addCountryWithAlt->setChecked(settings.value("AddCountryDomainWithAltKey", true).toBool()); settings.endGroup(); //BROWSING settings.beginGroup("Web-Browser-Settings"); - ui->allowPlugins->setChecked( settings.value("allowFlash", true).toBool() ); - ui->allowJavaScript->setChecked( settings.value("allowJavaScript", true).toBool() ); - ui->blockPopup->setChecked( !settings.value("allowJavaScriptOpenWindow", false).toBool() ); - ui->allowJava->setChecked( settings.value("allowJava", true).toBool() ); - ui->loadImages->setChecked( settings.value("autoLoadImages", true).toBool() ); - ui->allowDNSPrefetch->setChecked( settings.value("DNS-Prefetch", false).toBool() ); - ui->jscanAccessClipboard->setChecked( settings.value("JavaScriptCanAccessClipboard", true).toBool() ); - ui->linksInFocusChain->setChecked( settings.value("IncludeLinkInFocusChain", false).toBool() ); - ui->zoomTextOnly->setChecked( settings.value("zoomTextOnly", false).toBool() ); - ui->printEBackground->setChecked( settings.value("PrintElementBackground", true).toBool() ); - ui->wheelScroll->setValue( settings.value("wheelScrollLines", qApp->wheelScrollLines()).toInt() ); - ui->doNotTrack->setChecked( settings.value("DoNotTrack", false).toBool() ); - ui->defaultZoom->setValue( settings.value("DefaultZoom", 100).toInt() ); + ui->allowPlugins->setChecked(settings.value("allowFlash", true).toBool()); + ui->allowJavaScript->setChecked(settings.value("allowJavaScript", true).toBool()); + ui->blockPopup->setChecked(!settings.value("allowJavaScriptOpenWindow", false).toBool()); + ui->allowJava->setChecked(settings.value("allowJava", true).toBool()); + ui->loadImages->setChecked(settings.value("autoLoadImages", true).toBool()); + ui->allowDNSPrefetch->setChecked(settings.value("DNS-Prefetch", false).toBool()); + ui->jscanAccessClipboard->setChecked(settings.value("JavaScriptCanAccessClipboard", true).toBool()); + ui->linksInFocusChain->setChecked(settings.value("IncludeLinkInFocusChain", false).toBool()); + ui->zoomTextOnly->setChecked(settings.value("zoomTextOnly", false).toBool()); + ui->printEBackground->setChecked(settings.value("PrintElementBackground", true).toBool()); + ui->wheelScroll->setValue(settings.value("wheelScrollLines", qApp->wheelScrollLines()).toInt()); + ui->doNotTrack->setChecked(settings.value("DoNotTrack", false).toBool()); + ui->defaultZoom->setValue(settings.value("DefaultZoom", 100).toInt()); - if (!ui->allowJavaScript->isChecked()) + if (!ui->allowJavaScript->isChecked()) { ui->blockPopup->setEnabled(false); + } connect(ui->allowJavaScript, SIGNAL(toggled(bool)), this, SLOT(allowJavaScriptChanged(bool))); //Cache - ui->pagesInCache->setValue( settings.value("maximumCachedPages",3).toInt() ); + ui->pagesInCache->setValue(settings.value("maximumCachedPages", 3).toInt()); connect(ui->pagesInCache, SIGNAL(valueChanged(int)), this, SLOT(pageCacheValueChanged(int))); ui->pageCacheLabel->setText(QString::number(ui->pagesInCache->value())); - ui->allowCache->setChecked( settings.value("AllowLocalCache", true).toBool() ); - ui->cacheMB->setValue( settings.value("LocalCacheSize", 50).toInt() ); - ui->MBlabel->setText( settings.value("LocalCacheSize", 50).toString() + " MB"); + ui->allowCache->setChecked(settings.value("AllowLocalCache", true).toBool()); + ui->cacheMB->setValue(settings.value("LocalCacheSize", 50).toInt()); + ui->MBlabel->setText(settings.value("LocalCacheSize", 50).toString() + " MB"); connect(ui->allowCache, SIGNAL(clicked(bool)), this, SLOT(allowCacheChanged(bool))); - connect(ui->cacheMB, SIGNAL(valueChanged(int)), this, SLOT(cacheValueChanged(int)) ); + connect(ui->cacheMB, SIGNAL(valueChanged(int)), this, SLOT(cacheValueChanged(int))); allowCacheChanged(ui->allowCache->isChecked()); //PASSWORD MANAGER @@ -191,41 +198,45 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) //PRIVACY //Web storage - ui->storeIcons->setChecked( settings.value("allowPersistentStorage", true).toBool() ); - ui->saveHistory->setChecked( mApp->history()->isSaving() ); - ui->deleteHistoryOnClose->setChecked( settings.value("deleteHistoryOnClose", false).toBool() ); - if (!ui->saveHistory->isChecked()) + ui->storeIcons->setChecked(settings.value("allowPersistentStorage", true).toBool()); + ui->saveHistory->setChecked(mApp->history()->isSaving()); + ui->deleteHistoryOnClose->setChecked(settings.value("deleteHistoryOnClose", false).toBool()); + if (!ui->saveHistory->isChecked()) { ui->deleteHistoryOnClose->setEnabled(false); + } connect(ui->saveHistory, SIGNAL(toggled(bool)), this, SLOT(saveHistoryChanged(bool))); //Cookies - ui->saveCookies->setChecked( settings.value("allowCookies", true).toBool() ); - if (!ui->saveCookies->isChecked()) + ui->saveCookies->setChecked(settings.value("allowCookies", true).toBool()); + if (!ui->saveCookies->isChecked()) { ui->deleteCookiesOnClose->setEnabled(false); + } connect(ui->saveCookies, SIGNAL(toggled(bool)), this, SLOT(saveCookiesChanged(bool))); - ui->deleteCookiesOnClose->setChecked( settings.value("deleteCookiesOnClose", false).toBool() ); - ui->matchExactly->setChecked( settings.value("allowCookiesFromVisitedDomainOnly", false).toBool() ); - ui->filterTracking->setChecked( settings.value("filterTrackingCookie", false).toBool() ); + ui->deleteCookiesOnClose->setChecked(settings.value("deleteCookiesOnClose", false).toBool()); + ui->matchExactly->setChecked(settings.value("allowCookiesFromVisitedDomainOnly", false).toBool()); + ui->filterTracking->setChecked(settings.value("filterTrackingCookie", false).toBool()); //CSS Style - ui->userStyleSheet->setText( settings.value("userStyleSheet", "").toString() ); + ui->userStyleSheet->setText(settings.value("userStyleSheet", "").toString()); connect(ui->chooseUserStylesheet, SIGNAL(clicked()), this, SLOT(chooseUserStyleClicked())); settings.endGroup(); //DOWNLOADS settings.beginGroup("DownloadManager"); - ui->downLoc->setText( settings.value("defaultDownloadPath","").toString() ); - ui->closeDownManOnFinish->setChecked( settings.value("CloseManagerOnFinish", false).toBool() ); - ui->downlaodNativeSystemDialog->setChecked( settings.value("useNativeDialog", + ui->downLoc->setText(settings.value("defaultDownloadPath", "").toString()); + ui->closeDownManOnFinish->setChecked(settings.value("CloseManagerOnFinish", false).toBool()); + ui->downlaodNativeSystemDialog->setChecked(settings.value("useNativeDialog", #ifdef Q_WS_WIN - false + false #else - true + true #endif - ).toBool() ); - if (ui->downLoc->text().isEmpty()) + ).toBool()); + if (ui->downLoc->text().isEmpty()) { ui->askEverytime->setChecked(true); - else + } + else { ui->useDefined->setChecked(true); + } connect(ui->useDefined, SIGNAL(toggled(bool)), this, SLOT(downLocChanged(bool))); connect(ui->downButt, SIGNAL(clicked()), this, SLOT(chooseDownPath())); downLocChanged(ui->useDefined->isChecked()); @@ -233,15 +244,15 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) //FONTS settings.beginGroup("Browser-Fonts"); - ui->fontStandard->setCurrentFont(QFont( settings.value("StandardFont", mApp->webSettings()->fontFamily(QWebSettings::StandardFont)).toString() )); - ui->fontCursive->setCurrentFont(QFont( settings.value("CursiveFont", mApp->webSettings()->fontFamily(QWebSettings::CursiveFont)).toString() )); - ui->fontFantasy->setCurrentFont(QFont( settings.value("FantasyFont", mApp->webSettings()->fontFamily(QWebSettings::FantasyFont)).toString() )); - ui->fontFixed->setCurrentFont(QFont( settings.value("FixedFont", mApp->webSettings()->fontFamily(QWebSettings::FixedFont)).toString() )); - ui->fontSansSerif->setCurrentFont(QFont( settings.value("SansSerifFont", mApp->webSettings()->fontFamily(QWebSettings::SansSerifFont)).toString() )); - ui->fontSerif->setCurrentFont(QFont( settings.value("SerifFont", mApp->webSettings()->fontFamily(QWebSettings::SerifFont)).toString() )); + ui->fontStandard->setCurrentFont(QFont(settings.value("StandardFont", mApp->webSettings()->fontFamily(QWebSettings::StandardFont)).toString())); + ui->fontCursive->setCurrentFont(QFont(settings.value("CursiveFont", mApp->webSettings()->fontFamily(QWebSettings::CursiveFont)).toString())); + ui->fontFantasy->setCurrentFont(QFont(settings.value("FantasyFont", mApp->webSettings()->fontFamily(QWebSettings::FantasyFont)).toString())); + ui->fontFixed->setCurrentFont(QFont(settings.value("FixedFont", mApp->webSettings()->fontFamily(QWebSettings::FixedFont)).toString())); + ui->fontSansSerif->setCurrentFont(QFont(settings.value("SansSerifFont", mApp->webSettings()->fontFamily(QWebSettings::SansSerifFont)).toString())); + ui->fontSerif->setCurrentFont(QFont(settings.value("SerifFont", mApp->webSettings()->fontFamily(QWebSettings::SerifFont)).toString())); - ui->sizeDefault->setValue( settings.value("DefaultFontSize", mApp->webSettings()->fontSize(QWebSettings::DefaultFontSize)).toInt() ); - ui->sizeFixed->setValue( settings.value("FixedFontSize", mApp->webSettings()->fontSize(QWebSettings::DefaultFixedFontSize)).toInt() ); + ui->sizeDefault->setValue(settings.value("DefaultFontSize", mApp->webSettings()->fontSize(QWebSettings::DefaultFontSize)).toInt()); + ui->sizeFixed->setValue(settings.value("FixedFontSize", mApp->webSettings()->fontSize(QWebSettings::DefaultFixedFontSize)).toInt()); settings.endGroup(); //PLUGINS @@ -256,22 +267,24 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) settings.beginGroup("Notifications"); ui->notificationTimeout->setValue(settings.value("Timeout", 6000).toInt() / 1000); #ifdef Q_WS_X11 - notifyType = settings.value("UseNativeDesktop", true).toBool() ? DesktopNotificationsFactory::DesktopNative : DesktopNotificationsFactory::PopupWidget; + notifyType = settings.value("UseNativeDesktop", true).toBool() ? DesktopNotificationsFactory::DesktopNative : DesktopNotificationsFactory::PopupWidget; #else - notifyType = DesktopNotificationsFactory::PopupWidget; + notifyType = DesktopNotificationsFactory::PopupWidget; #endif - if (notifyType == DesktopNotificationsFactory::DesktopNative) + if (notifyType == DesktopNotificationsFactory::DesktopNative) { ui->useNativeSystemNotifications->setChecked(true); - else + } + else { ui->useOSDNotifications->setChecked(true); + } ui->doNotUseNotifications->setChecked(!settings.value("Enabled", true).toBool()); - m_notifPosition = settings.value("Position", QPoint(10,10)).toPoint(); + m_notifPosition = settings.value("Position", QPoint(10, 10)).toPoint(); settings.endGroup(); //OTHER //Languages - QString activeLanguage=""; + QString activeLanguage = ""; if (!p_QupZilla->activeLanguage().isEmpty()) { activeLanguage = p_QupZilla->activeLanguage(); QString loc = activeLanguage; @@ -279,22 +292,23 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) QLocale locale(loc); QString country = QLocale::countryToString(locale.country()); QString language = QLocale::languageToString(locale.language()); - ui->languages->addItem(language+", "+country+" ("+loc+")", activeLanguage); + ui->languages->addItem(language + ", " + country + " (" + loc + ")", activeLanguage); } ui->languages->addItem("English (en_US)"); QDir lanDir(mApp->TRANSLATIONSDIR); QStringList list = lanDir.entryList(QStringList("*.qm")); foreach(QString name, list) { - if (name.startsWith("qt_") || name == activeLanguage) + if (name.startsWith("qt_") || name == activeLanguage) { continue; + } QString loc = name; loc.remove(".qm"); QLocale locale(loc); QString country = QLocale::countryToString(locale.country()); QString language = QLocale::languageToString(locale.language()); - ui->languages->addItem(language+", "+country+" ("+loc+")", name); + ui->languages->addItem(language + ", " + country + " (" + loc + ")", name); } //Proxy Config settings.beginGroup("Web-Proxy"); @@ -306,10 +320,12 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) ui->noProxy->setChecked(proxyPreference == NetworkProxyFactory::NoProxy); ui->manualProxy->setChecked(proxyPreference == NetworkProxyFactory::DefinedProxy); setManualProxyConfigurationEnabled(proxyPreference == NetworkProxyFactory::DefinedProxy); - if (proxyType == QNetworkProxy::HttpProxy) + if (proxyType == QNetworkProxy::HttpProxy) { ui->proxyType->setCurrentIndex(0); - else + } + else { ui->proxyType->setCurrentIndex(1); + } ui->proxyServer->setText(settings.value("HostName", "").toString()); ui->proxyPort->setText(settings.value("Port", 8080).toString()); @@ -324,30 +340,32 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) connect(ui->sslManagerButton, SIGNAL(clicked()), this, SLOT(openSslManager())); connect(ui->preferredLanguages, SIGNAL(clicked()), this, SLOT(showAcceptLanguage())); - connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(showStackedPage(QListWidgetItem*))); - ui->listWidget->setItemSelected(ui->listWidget->itemAt(5,5), true); + connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(showStackedPage(QListWidgetItem*))); + ui->listWidget->setItemSelected(ui->listWidget->itemAt(5, 5), true); - ui->version->setText(" QupZilla v"+QupZilla::VERSION); + ui->version->setText(" QupZilla v" + QupZilla::VERSION); } void Preferences::showStackedPage(QListWidgetItem* item) { - if (!item) + if (!item) { return; - ui->caption->setText(""+item->text()+""); - ui->stackedWidget->setCurrentIndex(item->whatsThis().toInt()); + } + ui->caption->setText("" + item->text() + ""); + ui->stackedWidget->setCurrentIndex(item->whatsThis().toInt()); - if (ui->stackedWidget->currentIndex() == 8) { - m_notification = new DesktopNotification(true); - m_notification->setPixmap(QPixmap(":icons/preferences/stock_dialog-question.png")); - m_notification->setHeading(tr("OSD Notification")); - m_notification->setText(tr("Drag it on the screen to place it where you want.")); - m_notification->move(m_notifPosition); - m_notification->show(); - } else if (m_notification) { - m_notifPosition = m_notification->pos(); - delete m_notification; - } + if (ui->stackedWidget->currentIndex() == 8) { + m_notification = new DesktopNotification(true); + m_notification->setPixmap(QPixmap(":icons/preferences/stock_dialog-question.png")); + m_notification->setHeading(tr("OSD Notification")); + m_notification->setText(tr("Drag it on the screen to place it where you want.")); + m_notification->move(m_notifPosition); + m_notification->show(); + } + else if (m_notification) { + m_notifPosition = m_notification->pos(); + delete m_notification; + } } void Preferences::allowCacheChanged(bool state) { @@ -368,8 +386,9 @@ void Preferences::useActualNewTab() void Preferences::chooseDownPath() { QString userFileName = QFileDialog::getExistingDirectory(p_QupZilla, tr("Choose download location..."), QDir::homePath()); - if (userFileName.isEmpty()) + if (userFileName.isEmpty()) { return; + } #ifdef Q_WS_WIN //QFileDialog::getExistingDirectory returns path with \ instead of / (??) userFileName.replace("\\", "/"); #endif @@ -381,17 +400,20 @@ void Preferences::chooseDownPath() void Preferences::chooseUserStyleClicked() { QString file = QFileDialog::getOpenFileName(p_QupZilla, tr("Choose stylesheet location..."), QDir::homePath(), "*.css"); - if (file.isEmpty()) + if (file.isEmpty()) { return; + } ui->userStyleSheet->setText(file); } void Preferences::newTabChanged() { - if (ui->newTab->currentIndex() == 2) + if (ui->newTab->currentIndex() == 2) { ui->newTabFrame->setVisible(true); - else + } + else { ui->newTabFrame->setVisible(false); + } } void Preferences::downLocChanged(bool state) @@ -492,9 +514,10 @@ void Preferences::buttonClicked(QAbstractButton* button) void Preferences::createProfile() { QString name = QInputDialog::getText(this, tr("New Profile"), tr("Enter the new profile's name:")); - if (name.isEmpty() || name.contains("/") || name.contains("\\")) + if (name.isEmpty() || name.contains("/") || name.contains("\\")) { return; - QDir dir(QDir::homePath()+"/.qupzilla/profiles/"); + } + QDir dir(QDir::homePath() + "/.qupzilla/profiles/"); if (QDir(dir.absolutePath() + "/" + name).exists()) { QMessageBox::warning(this, tr("Error!"), tr("This profile already exists!")); return; @@ -504,7 +527,7 @@ void Preferences::createProfile() return; } dir.cd(name); - QFile(mApp->DATADIR+"data/default/profiles/default/browsedata.db").copy(dir.absolutePath()+"/browsedata.db"); + QFile(mApp->DATADIR + "data/default/profiles/default/browsedata.db").copy(dir.absolutePath() + "/browsedata.db"); ui->startProfile->insertItem(0, name); ui->startProfile->setCurrentIndex(0); @@ -514,11 +537,12 @@ void Preferences::deleteProfile() { QString name = ui->startProfile->currentText(); QMessageBox::StandardButton button = QMessageBox::warning(this, tr("Confirmation"), - tr("Are you sure to permanently delete \"%1\" profile? This action cannot be undone!").arg(name), QMessageBox::Yes | QMessageBox::No); - if (button != QMessageBox::Yes) + tr("Are you sure to permanently delete \"%1\" profile? This action cannot be undone!").arg(name), QMessageBox::Yes | QMessageBox::No); + if (button != QMessageBox::Yes) { return; + } - removeDir(QDir::homePath()+"/.qupzilla/profiles/"+name); + removeDir(QDir::homePath() + "/.qupzilla/profiles/" + name); ui->startProfile->removeItem(ui->startProfile->currentIndex()); } @@ -526,29 +550,34 @@ void Preferences::startProfileIndexChanged(QString index) { ui->deleteProfile->setEnabled(m_actProfileName != index); - if (m_actProfileName == index) + if (m_actProfileName == index) { ui->cannotDeleteActiveProfileLabel->setText(tr("Note: You cannot delete active profile.")); - else + } + else { ui->cannotDeleteActiveProfileLabel->setText(" "); + } } void Preferences::saveSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); //GENERAL URLs settings.beginGroup("Web-URL-Settings"); - settings.setValue("homepage",ui->homepage->text()); + settings.setValue("homepage", ui->homepage->text()); QString homepage = ui->homepage->text(); - settings.setValue("afterLaunch",ui->afterLaunch->currentIndex() ); + settings.setValue("afterLaunch", ui->afterLaunch->currentIndex()); - if (ui->newTab->currentIndex() == 0) - settings.setValue("newTabUrl",""); - else if (ui->newTab->currentIndex() == 1) - settings.setValue("newTabUrl",homepage); - else - settings.setValue("newTabUrl",ui->newTabUrl->text()); + if (ui->newTab->currentIndex() == 0) { + settings.setValue("newTabUrl", ""); + } + else if (ui->newTab->currentIndex() == 1) { + settings.setValue("newTabUrl", homepage); + } + else { + settings.setValue("newTabUrl", ui->newTabUrl->text()); + } settings.endGroup(); //PROFILES @@ -561,30 +590,32 @@ void Preferences::saveSettings() //WINDOW settings.beginGroup("Browser-View-Settings"); - settings.setValue("showStatusbar",ui->showStatusbar->isChecked()); + settings.setValue("showStatusbar", ui->showStatusbar->isChecked()); settings.setValue("showBookmarksToolbar", ui->showBookmarksToolbar->isChecked()); settings.setValue("showNavigationToolbar", ui->showNavigationToolbar->isChecked()); settings.setValue("showHomeButton", ui->showHome->isChecked()); - settings.setValue("showBackForwardButtons",ui->showBackForward->isChecked()); + settings.setValue("showBackForwardButtons", ui->showBackForward->isChecked()); settings.setValue("useTransparentBackground", ui->useTransparentBg->isChecked()); settings.setValue("showAddTabButton", ui->showAddTabButton->isChecked()); settings.endGroup(); //TABS settings.beginGroup("Browser-Tabs-Settings"); - settings.setValue("makeTabsMovable",ui->makeMovable->isChecked() ); - settings.setValue("hideCloseButtonWithOneTab",ui->hideCloseOnTab->isChecked()); - settings.setValue("hideTabsWithOneTab",ui->hideTabsOnTab->isChecked() ); + settings.setValue("makeTabsMovable", ui->makeMovable->isChecked()); + settings.setValue("hideCloseButtonWithOneTab", ui->hideCloseOnTab->isChecked()); + settings.setValue("hideTabsWithOneTab", ui->hideTabsOnTab->isChecked()); settings.setValue("ActivateLastTabWhenClosingActual", ui->activateLastTab->isChecked()); settings.setValue("AskOnClosing", ui->askWhenClosingMultipleTabs->isChecked()); settings.endGroup(); //DOWNLOADS settings.beginGroup("DownloadManager"); - if (ui->askEverytime->isChecked()) - settings.setValue("defaultDownloadPath",""); - else + if (ui->askEverytime->isChecked()) { + settings.setValue("defaultDownloadPath", ""); + } + else { settings.setValue("defaultDownloadPath", ui->downLoc->text()); + } settings.setValue("CloseManagerOnFinish", ui->closeDownManOnFinish->isChecked()); settings.setValue("useNativeDialog", ui->downlaodNativeSystemDialog->isChecked()); settings.endGroup(); @@ -630,13 +661,13 @@ void Preferences::saveSettings() //PRIVACY //Web storage settings.setValue("allowPersistentStorage", ui->storeIcons->isChecked()); - settings.setValue("deleteHistoryOnClose",ui->deleteHistoryOnClose->isChecked()); + settings.setValue("deleteHistoryOnClose", ui->deleteHistoryOnClose->isChecked()); //Cookies settings.setValue("allowCookies", ui->saveCookies->isChecked()); settings.setValue("deleteCookiesOnClose", ui->deleteCookiesOnClose->isChecked()); - settings.setValue("allowCookiesFromVisitedDomainOnly", ui->matchExactly->isChecked() ); - settings.setValue("filterTrackingCookie", ui->filterTracking->isChecked() ); + settings.setValue("allowCookiesFromVisitedDomainOnly", ui->matchExactly->isChecked()); + settings.setValue("filterTrackingCookie", ui->filterTracking->isChecked()); settings.endGroup(); //NOTIFICATIONS @@ -650,30 +681,35 @@ void Preferences::saveSettings() //OTHER //AddressBar settings.beginGroup("AddressBar"); - settings.setValue("SelectAllTextOnDoubleClick",ui->selectAllOnFocus->isChecked() ); - settings.setValue("AddComDomainWithCtrlKey",ui->addComWithCtrl->isChecked() ); - settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->isChecked() ); + settings.setValue("SelectAllTextOnDoubleClick", ui->selectAllOnFocus->isChecked()); + settings.setValue("AddComDomainWithCtrlKey", ui->addComWithCtrl->isChecked()); + settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->isChecked()); settings.endGroup(); //Languages settings.beginGroup("Language"); - settings.setValue("language",ui->languages->itemData(ui->languages->currentIndex()).toString()); + settings.setValue("language", ui->languages->itemData(ui->languages->currentIndex()).toString()); settings.endGroup(); //Proxy Configuration NetworkProxyFactory::ProxyPreference proxyPreference; - if (ui->systemProxy->isChecked()) + if (ui->systemProxy->isChecked()) { proxyPreference = NetworkProxyFactory::SystemProxy; - else if (ui->noProxy->isChecked()) + } + else if (ui->noProxy->isChecked()) { proxyPreference = NetworkProxyFactory::NoProxy; - else + } + else { proxyPreference = NetworkProxyFactory::DefinedProxy; + } QNetworkProxy::ProxyType proxyType; - if (ui->proxyType->currentIndex() == 0) + if (ui->proxyType->currentIndex() == 0) { proxyType = QNetworkProxy::HttpProxy; - else + } + else { proxyType = QNetworkProxy::Socks5Proxy; + } settings.beginGroup("Web-Proxy"); settings.setValue("ProxyType", proxyType); @@ -707,6 +743,7 @@ Preferences::~Preferences() delete ui; delete m_autoFillManager; delete m_pluginsList; - if (m_notification) + if (m_notification) { delete m_notification; + } } diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index 70153f462..4165d1d99 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -25,8 +25,9 @@ #include #include -namespace Ui { - class Preferences; +namespace Ui +{ +class Preferences; } class AutoFillManager; diff --git a/src/preferences/sslmanager.cpp b/src/preferences/sslmanager.cpp index ebe3992d8..5da985a24 100644 --- a/src/preferences/sslmanager.cpp +++ b/src/preferences/sslmanager.cpp @@ -53,8 +53,9 @@ SSLManager::SSLManager(QWidget* parent) void SSLManager::addPath() { QString path = QFileDialog::getExistingDirectory(this, tr("Choose path...")); - if (path.isEmpty()) + if (path.isEmpty()) { return; + } ui->pathList->addItem(path); } @@ -62,8 +63,9 @@ void SSLManager::addPath() void SSLManager::deletePath() { QListWidgetItem* currentItem = ui->pathList->currentItem(); - if (!currentItem) + if (!currentItem) { return; + } delete currentItem; } @@ -73,9 +75,9 @@ void SSLManager::refreshCAList() ui->caList->setUpdatesEnabled(false); ui->caList->clear(); m_caCerts = QSslSocket::defaultCaCertificates(); - foreach (QSslCertificate cert, m_caCerts) { + foreach(QSslCertificate cert, m_caCerts) { QListWidgetItem* item = new QListWidgetItem(ui->caList); - item->setText( CertificateInfoWidget::certificateItemText(cert) ); + item->setText(CertificateInfoWidget::certificateItemText(cert)); item->setWhatsThis(QString::number(m_caCerts.indexOf(cert))); ui->caList->addItem(item); } @@ -88,9 +90,9 @@ void SSLManager::refreshLocalList() ui->localList->setUpdatesEnabled(false); ui->localList->clear(); m_localCerts = mApp->networkManager()->getLocalCertificates(); - foreach (QSslCertificate cert, m_localCerts) { + foreach(QSslCertificate cert, m_localCerts) { QListWidgetItem* item = new QListWidgetItem(ui->localList); - item->setText( CertificateInfoWidget::certificateItemText(cert) ); + item->setText(CertificateInfoWidget::certificateItemText(cert)); item->setWhatsThis(QString::number(m_localCerts.indexOf(cert))); ui->localList->addItem(item); } @@ -100,15 +102,16 @@ void SSLManager::refreshLocalList() void SSLManager::refreshPaths() { - foreach (QString path, mApp->networkManager()->certificatePaths()) - ui->pathList->addItem(path); + foreach(QString path, mApp->networkManager()->certificatePaths()) + ui->pathList->addItem(path); } void SSLManager::showCaCertInfo() { QListWidgetItem* item = ui->caList->currentItem(); - if (!item) + if (!item) { return; + } QSslCertificate cert = m_caCerts.at(item->whatsThis().toInt()); showCertificateInfo(cert); @@ -117,8 +120,9 @@ void SSLManager::showCaCertInfo() void SSLManager::showLocalCertInfo() { QListWidgetItem* item = ui->localList->currentItem(); - if (!item) + if (!item) { return; + } QSslCertificate cert = m_localCerts.at(item->whatsThis().toInt()); showCertificateInfo(cert); @@ -144,8 +148,9 @@ void SSLManager::showCertificateInfo(const QSslCertificate &cert) void SSLManager::deleteCertificate() { QListWidgetItem* item = ui->localList->currentItem(); - if (!item) + if (!item) { return; + } QSslCertificate cert = m_localCerts.at(item->whatsThis().toInt()); m_localCerts.removeOne(cert); @@ -158,13 +163,14 @@ void SSLManager::ignoreAll(bool state) mApp->networkManager()->setIgnoreAllWarnings(state); } -void SSLManager::closeEvent(QCloseEvent *e) +void SSLManager::closeEvent(QCloseEvent* e) { QStringList paths; for (int i = 0; i < ui->pathList->count(); i++) { QListWidgetItem* item = ui->pathList->item(i); - if (!item || item->text().isEmpty()) + if (!item || item->text().isEmpty()) { continue; + } paths.append(item->text()); } diff --git a/src/preferences/sslmanager.h b/src/preferences/sslmanager.h index b7e7153bd..b5c26079c 100644 --- a/src/preferences/sslmanager.h +++ b/src/preferences/sslmanager.h @@ -27,8 +27,9 @@ #include #include -namespace Ui { - class SSLManager; +namespace Ui +{ +class SSLManager; } class SSLManager : public QDialog @@ -50,7 +51,7 @@ private slots: void deletePath(); private: - void closeEvent(QCloseEvent *e); + void closeEvent(QCloseEvent* e); void refreshLocalList(); void refreshCAList(); diff --git a/src/preferences/thememanager.cpp b/src/preferences/thememanager.cpp index 213bc5dd3..6e31196c6 100644 --- a/src/preferences/thememanager.cpp +++ b/src/preferences/thememanager.cpp @@ -26,7 +26,7 @@ ThemeManager::ThemeManager(QWidget* parent) { ui->setupUi(parent); ui->license->hide(); - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Themes"); m_activeTheme = settings.value("activeTheme", #ifdef Q_WS_X11 @@ -34,28 +34,30 @@ ThemeManager::ThemeManager(QWidget* parent) #else "windows" #endif - ).toString(); + ).toString(); settings.endGroup(); QDir themeDir(mApp->THEMESDIR); QStringList list = themeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); foreach(QString name, list) { Theme themeInfo = parseTheme(name); - if (!themeInfo.isValid) + if (!themeInfo.isValid) { continue; + } QListWidgetItem* item = new QListWidgetItem(ui->listWidget); item->setText(themeInfo.name + "\n" + themeInfo.shortDescription); item->setIcon(themeInfo.icon); item->setData(Qt::UserRole, name); - if (m_activeTheme == name) + if (m_activeTheme == name) { ui->listWidget->setCurrentItem(item); + } ui->listWidget->addItem(item); } - connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(currentChanged())); + connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(currentChanged())); connect(ui->license, SIGNAL(clicked(QPoint)), this, SLOT(showLicense())); currentChanged(); @@ -64,8 +66,9 @@ ThemeManager::ThemeManager(QWidget* parent) void ThemeManager::showLicense() { QListWidgetItem* currentItem = ui->listWidget->currentItem(); - if (!currentItem) + if (!currentItem) { return; + } Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()]; @@ -82,8 +85,9 @@ void ThemeManager::showLicense() void ThemeManager::currentChanged() { QListWidgetItem* currentItem = ui->listWidget->currentItem(); - if (!currentItem) + if (!currentItem) { return; + } Theme currentTheme = m_themeHash[currentItem->data(Qt::UserRole).toString()]; @@ -104,36 +108,43 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &name) return info; } - if (QFile(path + "theme.png").exists()) + if (QFile(path + "theme.png").exists()) { info.icon = QIcon(path + "theme.png"); - else + } + else { info.icon = QIcon(":icons/preferences/style-default.png"); + } - if (QFile(path + "theme.license").exists()) + if (QFile(path + "theme.license").exists()) { info.license = qz_readAllFileContents(path + "theme.license"); + } QString theme_info = qz_readAllFileContents(path + "theme.info"); QRegExp rx("Name:(.*)\\n"); rx.setMinimal(true); rx.indexIn(theme_info); - if (rx.captureCount() == 1) + if (rx.captureCount() == 1) { info.name = rx.cap(1).trimmed(); + } rx.setPattern("Author:(.*)\\n"); rx.indexIn(theme_info); - if (rx.captureCount() == 1) + if (rx.captureCount() == 1) { info.author = rx.cap(1).trimmed(); + } rx.setPattern("Short Description:(.*)\\n"); rx.indexIn(theme_info); - if (rx.captureCount() == 1) + if (rx.captureCount() == 1) { info.shortDescription = rx.cap(1).trimmed(); + } rx.setPattern("Long Description:(.*)\\n"); rx.indexIn(theme_info); - if (rx.captureCount() == 1) + if (rx.captureCount() == 1) { info.longDescription = rx.cap(1).trimmed(); + } info.isValid = true; m_themeHash.insert(name, info); @@ -142,7 +153,7 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &name) void ThemeManager::save() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Themes"); settings.setValue("activeTheme", ui->listWidget->currentItem()->data(Qt::UserRole)); settings.endGroup(); diff --git a/src/preferences/thememanager.h b/src/preferences/thememanager.h index bbc17fac6..2fe322c16 100644 --- a/src/preferences/thememanager.h +++ b/src/preferences/thememanager.h @@ -25,8 +25,9 @@ #include #include -namespace Ui { - class ThemeManager; +namespace Ui +{ +class ThemeManager; } class ThemeManager : public QWidget @@ -56,7 +57,7 @@ private: Theme parseTheme(const QString &name); - Ui::ThemeManager *ui; + Ui::ThemeManager* ui; QString m_activeTheme; QHash m_themeHash; }; diff --git a/src/rss/rssmanager.cpp b/src/rss/rssmanager.cpp index 156ac9168..2c9754e9e 100644 --- a/src/rss/rssmanager.cpp +++ b/src/rss/rssmanager.cpp @@ -45,15 +45,17 @@ RSSManager::RSSManager(QupZilla* mainClass, QWidget* parent) QupZilla* RSSManager::getQupZilla() { - if (!p_QupZilla) + if (!p_QupZilla) { p_QupZilla = mApp->getWindow(); + } return p_QupZilla; } void RSSManager::setMainWindow(QupZilla* window) { - if (window) + if (window) { p_QupZilla = window; + } } void RSSManager::refreshTable() @@ -73,14 +75,14 @@ void RSSManager::refreshTable() ui->tabWidget->addTab(tree, title); ui->tabWidget->setTabToolTip(i, address.toString()); - connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(loadFeed(QTreeWidgetItem*))); + connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(loadFeed(QTreeWidgetItem*))); connect(tree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(controlLoadFeed(QTreeWidgetItem*))); connect(tree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(controlLoadFeed(QTreeWidgetItem*))); QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, tr("Loading...")); tree->addTopLevelItem(item); - ui->tabWidget->setTabIcon(i, icon ); + ui->tabWidget->setTabIcon(i, icon); beginToLoadSlot(address); i++; } @@ -88,20 +90,21 @@ void RSSManager::refreshTable() ui->deletebutton->setEnabled(true); ui->reload->setEnabled(true); ui->edit->setEnabled(true); - } else { + } + else { ui->deletebutton->setEnabled(false); ui->reload->setEnabled(false); ui->edit->setEnabled(false); - QFrame *frame = new QFrame(); + QFrame* frame = new QFrame(); frame->setObjectName("rssmanager-frame"); - QVBoxLayout *verticalLayout = new QVBoxLayout(frame); - QLabel *label_2 = new QLabel(frame); + QVBoxLayout* verticalLayout = new QVBoxLayout(frame); + QLabel* label_2 = new QLabel(frame); label_2->setPixmap(QPixmap(":/icons/menu/rss.png")); - label_2->setAlignment(Qt::AlignBottom|Qt::AlignHCenter); + label_2->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); verticalLayout->addWidget(label_2); - QLabel *label = new QLabel(frame); - label->setAlignment(Qt::AlignHCenter|Qt::AlignTop); + QLabel* label = new QLabel(frame); + label->setAlignment(Qt::AlignHCenter | Qt::AlignTop); label->setText(tr("You don't have any RSS Feeds.
    \nPlease add some with RSS icon in navigation bar on site which offers feeds.")); verticalLayout->addWidget(label); ui->tabWidget->addTab(frame, tr("Empty")); @@ -111,34 +114,38 @@ void RSSManager::refreshTable() void RSSManager::reloadFeed() { TreeWidget* treeWidget = qobject_cast(ui->tabWidget->widget(ui->tabWidget->currentIndex())); - if (!treeWidget) + if (!treeWidget) { return; + } treeWidget->clear(); QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, tr("Loading...")); treeWidget->addTopLevelItem(item); - beginToLoadSlot( QUrl(ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex())) ); + beginToLoadSlot(QUrl(ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex()))); } void RSSManager::deleteFeed() { QString url = ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex()); - if (url.isEmpty()) + if (url.isEmpty()) { return; + } QSqlQuery query; - query.exec("DELETE FROM rss WHERE address='"+url+"'"); + query.exec("DELETE FROM rss WHERE address='" + url + "'"); ui->tabWidget->removeTab(ui->tabWidget->currentIndex()); - if (ui->tabWidget->count() == 0) + if (ui->tabWidget->count() == 0) { refreshTable(); + } } void RSSManager::editFeed() { QString url = ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex()); - if (url.isEmpty()) + if (url.isEmpty()) { return; + } QDialog* dialog = new QDialog(this); QFormLayout* layout = new QFormLayout(dialog); @@ -157,20 +164,22 @@ void RSSManager::editFeed() layout->addRow(new QLabel(tr("Feed URL: ")), editUrl); layout->addRow(box); - editUrl->setText( ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex()) ); - editTitle->setText( ui->tabWidget->tabText(ui->tabWidget->currentIndex()) ); + editUrl->setText(ui->tabWidget->tabToolTip(ui->tabWidget->currentIndex())); + editTitle->setText(ui->tabWidget->tabText(ui->tabWidget->currentIndex())); dialog->setWindowTitle(tr("Edit RSS Feed")); dialog->setMinimumSize(400, 100); dialog->exec(); - if (dialog->result() == QDialog::Rejected) + if (dialog->result() == QDialog::Rejected) { return; + } QString address = editUrl->text(); QString title = editTitle->text(); - if (address.isEmpty() || title.isEmpty()) + if (address.isEmpty() || title.isEmpty()) { return; + } QSqlQuery query; query.prepare("UPDATE rss SET address=?, title=? WHERE address=?"); @@ -186,15 +195,18 @@ void RSSManager::editFeed() void RSSManager::customContextMenuRequested(const QPoint &position) { TreeWidget* treeWidget = qobject_cast(ui->tabWidget->widget(ui->tabWidget->currentIndex())); - if (!treeWidget) + if (!treeWidget) { return; + } - if (!treeWidget->itemAt(position)) + if (!treeWidget->itemAt(position)) { return; + } QString link = treeWidget->itemAt(position)->toolTip(0); - if (link.isEmpty()) + if (link.isEmpty()) { return; + } QMenu menu; menu.addAction(tr("Open link in actual tab"), getQupZilla(), SLOT(loadActionUrl()))->setData(link); @@ -202,32 +214,37 @@ void RSSManager::customContextMenuRequested(const QPoint &position) //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu.exec(p); } void RSSManager::loadFeed(QTreeWidgetItem* item) { - if (!item) + if (!item) { return; - if (item->whatsThis(0).isEmpty()) + } + if (item->whatsThis(0).isEmpty()) { return; + } getQupZilla()->loadAddress(QUrl(item->whatsThis(0))); } void RSSManager::controlLoadFeed(QTreeWidgetItem* item) { - if (!item) + if (!item) { return; - if (item->whatsThis(0).isEmpty()) + } + if (item->whatsThis(0).isEmpty()) { return; + } getQupZilla()->tabWidget()->addView(QUrl(item->whatsThis(0)), tr("New Tab"), TabWidget::NewNotSelectedTab); } void RSSManager::loadFeedInNewTab() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { getQupZilla()->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab); + } } void RSSManager::beginToLoadSlot(const QUrl &url) @@ -244,8 +261,9 @@ void RSSManager::beginToLoadSlot(const QUrl &url) void RSSManager::finished() { FollowRedirectReply* reply = qobject_cast (sender()); - if (!reply) + if (!reply) { return; + } QString replyUrl; for (int i = 0; i < m_replies.count(); i++) { @@ -256,8 +274,9 @@ void RSSManager::finished() } } - if (replyUrl.isEmpty()) + if (replyUrl.isEmpty()) { return; + } QString currentTag; QString linkString; @@ -268,45 +287,52 @@ void RSSManager::finished() delete reply; int tabIndex = -1; - for (int i=0; itabWidget->count(); i++) { + for (int i = 0; i < ui->tabWidget->count(); i++) { if (replyUrl == ui->tabWidget->tabToolTip(i)) { tabIndex = i; break; } } - if (tabIndex == -1) + if (tabIndex == -1) { return; + } TreeWidget* treeWidget = qobject_cast(ui->tabWidget->widget(tabIndex)); - if (!treeWidget) + if (!treeWidget) { return; + } treeWidget->clear(); while (!xml.atEnd()) { xml.readNext(); if (xml.isStartElement()) { - if (xml.name() == "item") + if (xml.name() == "item") { linkString = xml.attributes().value("rss:about").toString(); - currentTag = xml.name().toString(); - } else if (xml.isEndElement()) { - if (xml.name() == "item") { - QTreeWidgetItem* item = new QTreeWidgetItem; - item->setText(0, titleString); - item->setWhatsThis(0, linkString); - item->setIcon(0, QIcon(":/icons/other/feed.png")); - item->setToolTip(0, linkString); - treeWidget->addTopLevelItem(item); - - titleString.clear(); - linkString.clear(); - } - } else if (xml.isCharacters() && !xml.isWhitespace()) { - if (currentTag == "title") - titleString = xml.text().toString(); - else if (currentTag == "link") - linkString += xml.text().toString(); } + currentTag = xml.name().toString(); + } + else if (xml.isEndElement()) { + if (xml.name() == "item") { + QTreeWidgetItem* item = new QTreeWidgetItem; + item->setText(0, titleString); + item->setWhatsThis(0, linkString); + item->setIcon(0, QIcon(":/icons/other/feed.png")); + item->setToolTip(0, linkString); + treeWidget->addTopLevelItem(item); + + titleString.clear(); + linkString.clear(); + } + } + else if (xml.isCharacters() && !xml.isWhitespace()) { + if (currentTag == "title") { + titleString = xml.text().toString(); + } + else if (currentTag == "link") { + linkString += xml.text().toString(); + } + } } if (treeWidget->topLevelItemCount() == 0) { @@ -318,16 +344,19 @@ void RSSManager::finished() bool RSSManager::addRssFeed(const QString &address, const QString &title, const QIcon &icon) { - if (address.isEmpty()) + if (address.isEmpty()) { return false; + } QSqlQuery query; - query.exec("SELECT id FROM rss WHERE address='"+address+"'"); + query.exec("SELECT id FROM rss WHERE address='" + address + "'"); if (!query.next()) { QByteArray iconData; - if (icon.pixmap(16,16).toImage() == QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic).toImage()) + if (icon.pixmap(16, 16).toImage() == QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic).toImage()) { iconData = IconProvider::iconToBase64(QIcon(":icons/other/feed.png")); - else + } + else { iconData = IconProvider::iconToBase64(icon); + } query.prepare("INSERT INTO rss (address, title, icon) VALUES(?,?,?)"); query.bindValue(0, address); @@ -344,8 +373,9 @@ bool RSSManager::addRssFeed(const QString &address, const QString &title, const void RSSManager::optimizeDb() { BrowsingLibrary* b = qobject_cast(parentWidget()->parentWidget()); - if (!b) + if (!b) { return; + } b->optimizeDatabase(); } diff --git a/src/rss/rssmanager.h b/src/rss/rssmanager.h index 98fc3f343..e1e8dce19 100644 --- a/src/rss/rssmanager.h +++ b/src/rss/rssmanager.h @@ -26,8 +26,9 @@ #include #include -namespace Ui { - class RSSManager; +namespace Ui +{ +class RSSManager; } class FollowRedirectReply; diff --git a/src/rss/rssnotification.h b/src/rss/rssnotification.h index 5eb84ff93..4b412358c 100644 --- a/src/rss/rssnotification.h +++ b/src/rss/rssnotification.h @@ -22,8 +22,9 @@ #include "animatedwidget.h" -namespace Ui { - class RSSNotification; +namespace Ui +{ +class RSSNotification; } class AnimatedWidget; diff --git a/src/rss/rsswidget.cpp b/src/rss/rsswidget.cpp index 9f087dfcd..3d0fb2d7d 100644 --- a/src/rss/rsswidget.cpp +++ b/src/rss/rsswidget.cpp @@ -36,8 +36,9 @@ RSSWidget::RSSWidget(WebView* view, QWidget* parent) QWebElement element = links.at(i); QString title = element.attribute("title"); QString href = element.attribute("href"); - if (href.isEmpty() || title.isEmpty()) + if (href.isEmpty() || title.isEmpty()) { continue; + } QPushButton* button = new QPushButton(this); button->setText(tr("Add")); @@ -54,36 +55,43 @@ RSSWidget::RSSWidget(WebView* view, QWidget* parent) void RSSWidget::showAt(QWidget* _parent) { QPoint p = _parent->mapToGlobal(QPoint(0, 0)); - move( (p.x()+_parent->width() - width() ), p.y() + _parent->height()); + move((p.x() + _parent->width() - width()), p.y() + _parent->height()); show(); } void RSSWidget::addRss() { - if(!m_view) + if (!m_view) { return; + } if (QPushButton* button = qobject_cast(sender())) { QUrl url = QUrl(button->whatsThis()); QString urlString = button->whatsThis(); - if(url.host().isEmpty()) { - if(!urlString.startsWith("/")) - urlString="/"+urlString; - urlString = m_view->url().host()+urlString; + if (url.host().isEmpty()) { + if (!urlString.startsWith("/")) { + urlString = "/" + urlString; + } + urlString = m_view->url().host() + urlString; QUrl temp(urlString); - if(temp.scheme().isEmpty()) - urlString="http://"+urlString; + if (temp.scheme().isEmpty()) { + urlString = "http://" + urlString; + } temp = QUrl(urlString); - if(temp.scheme().isEmpty() || temp.host().isEmpty()) + if (temp.scheme().isEmpty() || temp.host().isEmpty()) { return; + } } - if (!url.isValid()) + if (!url.isValid()) { return; + } QString title; - if (button->toolTip().isEmpty()) + if (button->toolTip().isEmpty()) { title = m_view->url().host(); - else + } + else { title = button->toolTip(); + } if (mApp->rssManager()->addRssFeed(urlString, title, m_view->siteIcon())) { RSSNotification* notif = new RSSNotification(title, m_view); diff --git a/src/rss/rsswidget.h b/src/rss/rsswidget.h index 65ae95fb0..d0023e861 100644 --- a/src/rss/rsswidget.h +++ b/src/rss/rsswidget.h @@ -24,8 +24,9 @@ #include #include -namespace Ui { - class RSSWidget; +namespace Ui +{ +class RSSWidget; } class WebView; diff --git a/src/sidebar/bookmarkssidebar.cpp b/src/sidebar/bookmarkssidebar.cpp index 4ce10121b..f45a5332f 100644 --- a/src/sidebar/bookmarkssidebar.cpp +++ b/src/sidebar/bookmarkssidebar.cpp @@ -38,50 +38,55 @@ BookmarksSideBar::BookmarksSideBar(QupZilla* mainClass, QWidget* parent) connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &))); connect(ui->bookmarksTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*))); connect(ui->bookmarksTree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*))); - connect(ui->bookmarksTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); + connect(ui->bookmarksTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); connect(ui->search, SIGNAL(textChanged(QString)), ui->bookmarksTree, SLOT(filterString(QString))); connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(addBookmark(BookmarksModel::Bookmark))); connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(removeBookmark(BookmarksModel::Bookmark))); - connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark))); + connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark))); connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString))); connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString))); - connect(m_bookmarksModel, SIGNAL(folderRenamed(QString,QString)), this, SLOT(renameFolder(QString,QString))); + connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString))); QTimer::singleShot(0, this, SLOT(refreshTable())); } void BookmarksSideBar::itemControlClicked(QTreeWidgetItem* item) { - if (!item || item->text(1).isEmpty()) + if (!item || item->text(1).isEmpty()) { return; + } p_QupZilla->tabWidget()->addView(QUrl(item->text(1))); } -void BookmarksSideBar::itemDoubleClicked(QTreeWidgetItem *item) +void BookmarksSideBar::itemDoubleClicked(QTreeWidgetItem* item) { - if (!item || item->text(1).isEmpty()) + if (!item || item->text(1).isEmpty()) { return; + } p_QupZilla->loadAddress(QUrl(item->text(1))); } void BookmarksSideBar::loadInNewTab() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { p_QupZilla->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab); + } } void BookmarksSideBar::copyAddress() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { QApplication::clipboard()->setText(action->data().toString()); + } } void BookmarksSideBar::deleteItem() { QTreeWidgetItem* item = ui->bookmarksTree->currentItem(); - if (!item) + if (!item) { return; + } int id = item->whatsThis(0).toInt(); m_bookmarksModel->removeBookmark(id); @@ -89,11 +94,13 @@ void BookmarksSideBar::deleteItem() void BookmarksSideBar::contextMenuRequested(const QPoint &position) { - if (!ui->bookmarksTree->itemAt(position)) + if (!ui->bookmarksTree->itemAt(position)) { return; + } QString link = ui->bookmarksTree->itemAt(position)->text(1); - if (link.isEmpty()) + if (link.isEmpty()) { return; + } QMenu menu; menu.addAction(tr("Open link in actual &tab"), p_QupZilla, SLOT(loadActionUrl()))->setData(link); @@ -104,7 +111,7 @@ void BookmarksSideBar::contextMenuRequested(const QPoint &position) //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu.exec(p); } @@ -118,35 +125,43 @@ void BookmarksSideBar::addBookmark(const BookmarksModel::Bookmark &bookmark) item->setIcon(0, bookmark.icon); item->setToolTip(0, bookmark.url.toEncoded()); - if (bookmark.folder != "unsorted") + if (bookmark.folder != "unsorted") { ui->bookmarksTree->appendToParentItem(translatedFolder, item); - else + } + else { ui->bookmarksTree->addTopLevelItem(item); + } // if (!ui->search->text().isEmpty()) - item->setHidden(!bookmark.title.contains(ui->search->text(), Qt::CaseInsensitive)); + item->setHidden(!bookmark.title.contains(ui->search->text(), Qt::CaseInsensitive)); } void BookmarksSideBar::removeBookmark(const BookmarksModel::Bookmark &bookmark) { if (bookmark.folder == "unsorted") { QList list = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* item = list.at(0); - if (item && item->whatsThis(0) == QString::number(bookmark.id)) + if (item && item->whatsThis(0) == QString::number(bookmark.id)) { ui->bookmarksTree->deleteItem(item); - } else { + } + } + else { QList list = ui->bookmarksTree->findItems(BookmarksModel::toTranslatedFolder(bookmark.folder), Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* parentItem = list.at(0); - if (!parentItem) + if (!parentItem) { return; + } for (int i = 0; i < parentItem->childCount(); i++) { QTreeWidgetItem* item = parentItem->child(i); - if (!item) + if (!item) { continue; + } if (item->text(0) == bookmark.title && item->whatsThis(0) == QString::number(bookmark.id)) { ui->bookmarksTree->deleteItem(item); return; @@ -171,21 +186,25 @@ void BookmarksSideBar::addFolder(const QString &name) void BookmarksSideBar::removeFolder(const QString &name) { QList list = ui->bookmarksTree->findItems(name, Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* item = list.at(0); - if (item) + if (item) { ui->bookmarksTree->deleteItem(item); + } } void BookmarksSideBar::renameFolder(const QString &before, const QString &after) { QList list = ui->bookmarksTree->findItems(before, Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return; + } QTreeWidgetItem* item = list.at(0); - if (!item) + if (!item) { return; + } item->setText(0, after); } @@ -203,7 +222,7 @@ void BookmarksSideBar::refreshTable() ui->bookmarksTree->addTopLevelItem(newItem); query.exec("SELECT name FROM folders WHERE subfolder!='yes'"); - while(query.next()) { + while (query.next()) { newItem = new QTreeWidgetItem(ui->bookmarksTree); newItem->setText(0, query.value(0).toString()); newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon)); @@ -211,27 +230,32 @@ void BookmarksSideBar::refreshTable() } query.exec("SELECT title, url, id, folder, icon FROM bookmarks"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); int id = query.value(2).toInt(); QString folder = query.value(3).toString(); QIcon icon = IconProvider::iconFromBase64(query.value(4).toByteArray()); QTreeWidgetItem* item; - if (folder == "bookmarksMenu") + if (folder == "bookmarksMenu") { folder = tr("Bookmarks In Menu"); - if (folder == "bookmarksToolbar") + } + if (folder == "bookmarksToolbar") { continue; + } if (folder != "unsorted") { QList findParent = ui->bookmarksTree->findItems(folder, 0); - if (findParent.count() != 1) + if (findParent.count() != 1) { continue; + } item = new QTreeWidgetItem(findParent.at(0)); - } else + } + else { item = new QTreeWidgetItem(ui->bookmarksTree); + } item->setText(0, title); item->setText(1, url.toEncoded()); diff --git a/src/sidebar/bookmarkssidebar.h b/src/sidebar/bookmarkssidebar.h index 1b62af0b2..873e39db0 100644 --- a/src/sidebar/bookmarkssidebar.h +++ b/src/sidebar/bookmarkssidebar.h @@ -24,8 +24,9 @@ #include "bookmarksmodel.h" -namespace Ui { - class BookmarksSideBar; +namespace Ui +{ +class BookmarksSideBar; } class WebView; diff --git a/src/sidebar/historysidebar.cpp b/src/sidebar/historysidebar.cpp index bec728f1a..6779e0acb 100644 --- a/src/sidebar/historysidebar.cpp +++ b/src/sidebar/historysidebar.cpp @@ -23,12 +23,12 @@ HistorySideBar::HistorySideBar(QupZilla* mainClass, QWidget* parent) : QWidget(parent) - ,ui(new Ui::HistorySideBar) - ,p_QupZilla(mainClass) - ,m_historyModel(mApp->history()) + , ui(new Ui::HistorySideBar) + , p_QupZilla(mainClass) + , m_historyModel(mApp->history()) { ui->setupUi(this); - connect(ui->historyTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); + connect(ui->historyTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*))); connect(ui->historyTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*))); connect(ui->historyTree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*))); @@ -38,7 +38,7 @@ HistorySideBar::HistorySideBar(QupZilla* mainClass, QWidget* parent) : connect(m_historyModel, SIGNAL(historyEntryAdded(HistoryModel::HistoryEntry)), this, SLOT(historyEntryAdded(HistoryModel::HistoryEntry))); connect(m_historyModel, SIGNAL(historyEntryDeleted(HistoryModel::HistoryEntry)), this, SLOT(historyEntryDeleted(HistoryModel::HistoryEntry))); - connect(m_historyModel, SIGNAL(historyEntryEdited(HistoryModel::HistoryEntry,HistoryModel::HistoryEntry)), this, SLOT(historyEntryEdited(HistoryModel::HistoryEntry,HistoryModel::HistoryEntry))); + connect(m_historyModel, SIGNAL(historyEntryEdited(HistoryModel::HistoryEntry, HistoryModel::HistoryEntry)), this, SLOT(historyEntryEdited(HistoryModel::HistoryEntry, HistoryModel::HistoryEntry))); connect(m_historyModel, SIGNAL(historyClear()), ui->historyTree, SLOT(clear())); QTimer::singleShot(0, this, SLOT(refreshTable())); @@ -46,37 +46,43 @@ HistorySideBar::HistorySideBar(QupZilla* mainClass, QWidget* parent) : void HistorySideBar::itemDoubleClicked(QTreeWidgetItem* item) { - if (!item || item->text(1).isEmpty()) + if (!item || item->text(1).isEmpty()) { return; + } p_QupZilla->loadAddress(QUrl(item->text(1))); } void HistorySideBar::itemControlClicked(QTreeWidgetItem* item) { - if (!item || item->text(1).isEmpty()) + if (!item || item->text(1).isEmpty()) { return; + } p_QupZilla->tabWidget()->addView(QUrl(item->text(1))); } void HistorySideBar::loadInNewTab() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { p_QupZilla->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab); + } } void HistorySideBar::copyAddress() { - if (QAction* action = qobject_cast(sender())) + if (QAction* action = qobject_cast(sender())) { QApplication::clipboard()->setText(action->data().toString()); + } } void HistorySideBar::contextMenuRequested(const QPoint &position) { - if (!ui->historyTree->itemAt(position)) + if (!ui->historyTree->itemAt(position)) { return; + } QString link = ui->historyTree->itemAt(position)->text(1); - if (link.isEmpty()) + if (link.isEmpty()) { return; + } QMenu menu; menu.addAction(tr("Open link in actual tab"), p_QupZilla, SLOT(loadActionUrl()))->setData(link); @@ -85,7 +91,7 @@ void HistorySideBar::contextMenuRequested(const QPoint &position) //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu.exec(p); } @@ -97,21 +103,26 @@ void HistorySideBar::historyEntryAdded(const HistoryModel::HistoryEntry &entry) QDate date = entry.date.date(); QString localDate; - if (date == todayDate) + if (date == todayDate) { localDate = tr("Today"); - else if (date >= startOfWeekDate) + } + else if (date >= startOfWeekDate) { localDate = tr("This Week"); - else if (date.month() == todayDate.month()) + } + else if (date.month() == todayDate.month()) { localDate = tr("This Month"); - else + } + else { localDate = QString("%1 %2").arg(HistoryModel::titleCaseLocalizedMonth(date.month()), QString::number(date.year())); + } QTreeWidgetItem* item = new QTreeWidgetItem(); QTreeWidgetItem* parentItem; QList findParent = ui->historyTree->findItems(localDate, 0); if (findParent.count() == 1) { parentItem = findParent.at(0); - } else { + } + else { parentItem = new QTreeWidgetItem(); parentItem->setText(0, localDate); parentItem->setIcon(0, QIcon(":/icons/menu/history_entry.png")); @@ -130,11 +141,13 @@ void HistorySideBar::historyEntryAdded(const HistoryModel::HistoryEntry &entry) void HistorySideBar::historyEntryDeleted(const HistoryModel::HistoryEntry &entry) { QList list = ui->historyTree->allItems(); - foreach (QTreeWidgetItem* item, list) { - if (!item) + foreach(QTreeWidgetItem * item, list) { + if (!item) { continue; - if (item->whatsThis(1).toInt() != entry.id) + } + if (item->whatsThis(1).toInt() != entry.id) { continue; + } ui->historyTree->deleteItem(item); return; } @@ -151,17 +164,19 @@ void HistorySideBar::search() QString searchText = ui->search->text(); refreshTable(); - if (searchText.isEmpty()) + if (searchText.isEmpty()) { return; + } ui->historyTree->setUpdatesEnabled(false); - QList items = ui->historyTree->findItems("*"+searchText+"*", Qt::MatchRecursive | Qt::MatchWildcard); + QList items = ui->historyTree->findItems("*" + searchText + "*", Qt::MatchRecursive | Qt::MatchWildcard); QList foundItems; - foreach(QTreeWidgetItem* fitem, items) { - if (fitem->text(1).isEmpty()) + foreach(QTreeWidgetItem * fitem, items) { + if (fitem->text(1).isEmpty()) { continue; + } QTreeWidgetItem* item = new QTreeWidgetItem(); item->setText(0, fitem->text(0)); item->setText(1, fitem->text(1)); @@ -184,27 +199,32 @@ void HistorySideBar::refreshTable() QSqlQuery query; query.exec("SELECT title, url, id, date FROM history ORDER BY date DESC"); - while(query.next()) { + while (query.next()) { QString title = query.value(0).toString(); QUrl url = query.value(1).toUrl(); int id = query.value(2).toInt(); QDate date = QDateTime::fromMSecsSinceEpoch(query.value(3).toLongLong()).date(); QString localDate; - if (date == todayDate) + if (date == todayDate) { localDate = tr("Today"); - else if (date >= startOfWeekDate) + } + else if (date >= startOfWeekDate) { localDate = tr("This Week"); - else if (date.month() == todayDate.month()) + } + else if (date.month() == todayDate.month()) { localDate = tr("This Month"); - else + } + else { localDate = QString("%1 %2").arg(HistoryModel::titleCaseLocalizedMonth(date.month()), QString::number(date.year())); + } QTreeWidgetItem* item; QList findParent = ui->historyTree->findItems(localDate, 0); if (findParent.count() == 1) { item = new QTreeWidgetItem(findParent.at(0)); - }else{ + } + else { QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->historyTree); newParent->setText(0, localDate); newParent->setIcon(0, QIcon(":/icons/menu/history_entry.png")); diff --git a/src/sidebar/historysidebar.h b/src/sidebar/historysidebar.h index 54f8a594e..90b34ee0f 100644 --- a/src/sidebar/historysidebar.h +++ b/src/sidebar/historysidebar.h @@ -25,8 +25,9 @@ #include "historymodel.h" -namespace Ui { - class HistorySideBar; +namespace Ui +{ +class HistorySideBar; } class QupZilla; diff --git a/src/sidebar/sidebar.cpp b/src/sidebar/sidebar.cpp index cb328139d..8c67701a9 100644 --- a/src/sidebar/sidebar.cpp +++ b/src/sidebar/sidebar.cpp @@ -67,8 +67,9 @@ void SideBar::showRSS() void SideBar::setWidget(QWidget* widget) { - if (m_layout->count() == 2) + if (m_layout->count() == 2) { delete m_layout->itemAt(1)->widget(); + } m_layout->addWidget(widget); } diff --git a/src/tools/animatedwidget.cpp b/src/tools/animatedwidget.cpp index c0fa7646b..9502e8298 100644 --- a/src/tools/animatedwidget.cpp +++ b/src/tools/animatedwidget.cpp @@ -21,6 +21,8 @@ AnimatedWidget::AnimatedWidget(const Direction &direction, int duration, QWidget* parent) : QWidget(parent) , m_widget(new QWidget(this)) + , Y_SHOWN(0) + , Y_HIDDEN(0) , m_direction(direction) { m_positionAni = new QPropertyAnimation(m_widget, "pos"); @@ -41,7 +43,8 @@ void AnimatedWidget::startAnimation() if (m_direction == Down) { Y_SHOWN = 0; Y_HIDDEN = -m_widget->height(); - } else if (m_direction == Up) { + } + else if (m_direction == Up) { Y_SHOWN = 0; Y_HIDDEN = 0; } @@ -63,10 +66,11 @@ void AnimatedWidget::hide() connect(m_aniGroup, SIGNAL(finished()), this, SLOT(close())); } -void AnimatedWidget::resizeEvent(QResizeEvent *event) +void AnimatedWidget::resizeEvent(QResizeEvent* event) { - if (event->size().width() != m_widget->width()) + if (event->size().width() != m_widget->width()) { m_widget->resize(event->size().width(), m_widget->height()); + } QWidget::resizeEvent(event); } diff --git a/src/tools/animatedwidget.h b/src/tools/animatedwidget.h index eb0917249..2e67ae14a 100644 --- a/src/tools/animatedwidget.h +++ b/src/tools/animatedwidget.h @@ -40,7 +40,7 @@ public slots: void startAnimation(); private: - void resizeEvent(QResizeEvent *e); + void resizeEvent(QResizeEvent* e); QPropertyAnimation* m_positionAni; QPropertyAnimation* m_heightAni; diff --git a/src/tools/buttonbox.cpp b/src/tools/buttonbox.cpp index 2f6704064..54c7b1b7a 100644 --- a/src/tools/buttonbox.cpp +++ b/src/tools/buttonbox.cpp @@ -17,14 +17,14 @@ * ============================================================ */ #include "buttonbox.h" -ButtonBox::ButtonBox(QWidget *parent) : +ButtonBox::ButtonBox(QWidget* parent) : QDialogButtonBox(parent) - , m_clickedButton(QDialogButtonBox::RejectRole) + , m_clickedButton(QDialogButtonBox::RejectRole) { connect(this, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); } -void ButtonBox::buttonClicked(QAbstractButton *button) +void ButtonBox::buttonClicked(QAbstractButton* button) { m_clickedButton = buttonRole(button); } diff --git a/src/tools/buttonbox.h b/src/tools/buttonbox.h index 20db3a2c4..1a6953acb 100644 --- a/src/tools/buttonbox.h +++ b/src/tools/buttonbox.h @@ -25,7 +25,7 @@ class ButtonBox : public QDialogButtonBox { Q_OBJECT public: - explicit ButtonBox(QWidget *parent = 0); + explicit ButtonBox(QWidget* parent = 0); ButtonRole clickedButtonRole(); signals: diff --git a/src/tools/buttonwithmenu.cpp b/src/tools/buttonwithmenu.cpp index 1df6cfecf..815914b12 100644 --- a/src/tools/buttonwithmenu.cpp +++ b/src/tools/buttonwithmenu.cpp @@ -19,8 +19,8 @@ ButtonWithMenu::ButtonWithMenu(QWidget* parent) : ToolButton(parent) - , m_menu(new QMenu(this)) - , m_currentItem(0) + , m_menu(new QMenu(this)) + , m_currentItem(0) { setPopupMode(QToolButton::InstantPopup); setCursor(Qt::ArrowCursor); @@ -49,15 +49,16 @@ void ButtonWithMenu::addItem(const Item &item) { m_items.append(item); - if (!m_currentItem) + if (!m_currentItem) { setCurrentItem(item); + } emit itemAdded(item); } void ButtonWithMenu::addItems(const QList &items) { - foreach (const Item &item, items) { + foreach(const Item & item, items) { addItem(item); } } @@ -65,8 +66,9 @@ void ButtonWithMenu::addItems(const QList &items) void ButtonWithMenu::removeItem(const Item &item) { int index = m_items.indexOf(item); - if (index < 0) + if (index < 0) { return; + } m_items.removeOne(item); @@ -75,15 +77,17 @@ void ButtonWithMenu::removeItem(const Item &item) return; } - if (*m_currentItem == item) + if (*m_currentItem == item) { setCurrentItem(m_items.first()); + } } void ButtonWithMenu::setCurrentItem(const Item &item) { int index = m_items.indexOf(item); - if (index < 0) + if (index < 0) { return; + } m_currentItem = const_cast(&m_items.at(index)); @@ -93,23 +97,26 @@ void ButtonWithMenu::setCurrentItem(const Item &item) emit activeItemChanged(*m_currentItem); } -void ButtonWithMenu::wheelEvent(QWheelEvent *event) +void ButtonWithMenu::wheelEvent(QWheelEvent* event) { int currItemIndex = m_items.indexOf(*m_currentItem); int itemsCount = m_items.count(); - if (itemsCount == 0) + if (itemsCount == 0) { return; + } int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; if (numSteps == 1) { - if (currItemIndex != 0) + if (currItemIndex != 0) { setCurrentItem(m_items.at(currItemIndex - 1)); - } else { - if (currItemIndex < itemsCount - 1) + } + } + else if (currItemIndex < itemsCount - 1) { setCurrentItem(m_items.at(currItemIndex + 1)); } + event->accept(); } @@ -127,7 +134,7 @@ void ButtonWithMenu::generateMenu() { m_menu->clear(); - foreach (Item item, m_items) { + foreach(Item item, m_items) { QVariant variant; variant.setValue(item); m_menu->addAction(item.icon, item.text, this, SLOT(setCurrentItem()))->setData(variant); diff --git a/src/tools/buttonwithmenu.h b/src/tools/buttonwithmenu.h index 1c713c2be..bc0105628 100644 --- a/src/tools/buttonwithmenu.h +++ b/src/tools/buttonwithmenu.h @@ -34,15 +34,13 @@ public: QIcon icon; QVariant userData; - Item(const QString &a = QString(), const QIcon &b = QIcon()) - { + Item(const QString &a = QString(), const QIcon &b = QIcon()) { text = a; icon = b; } - bool operator==(const Item &a) - { - return (a.text == text) && (a.icon.pixmap(16,16).toImage() == icon.pixmap(16,16).toImage()); + bool operator==(const Item &a) { + return (a.text == text) && (a.icon.pixmap(16, 16).toImage() == icon.pixmap(16, 16).toImage()); } }; @@ -71,7 +69,7 @@ private slots: void generateMenu(); private: - void wheelEvent(QWheelEvent *event); + void wheelEvent(QWheelEvent* event); QMenu* m_menu; QList m_items; diff --git a/src/tools/certificateinfowidget.cpp b/src/tools/certificateinfowidget.cpp index ccfc3b341..1ca839de3 100644 --- a/src/tools/certificateinfowidget.cpp +++ b/src/tools/certificateinfowidget.cpp @@ -23,8 +23,9 @@ QString CertificateInfoWidget::certificateItemText(const QSslCertificate &cert) QString commonName = cert.subjectInfo(QSslCertificate::CommonName); QString organization = cert.subjectInfo(QSslCertificate::Organization); - if (commonName.isEmpty()) + if (commonName.isEmpty()) { return clearCertSpecialSymbols(organization); + } return clearCertSpecialSymbols(commonName); } @@ -33,64 +34,227 @@ QString CertificateInfoWidget::clearCertSpecialSymbols(const QString &string) { QString n = Qt::escape(string); - if (!n.contains("\\")) + if (!n.contains("\\")) { return n; + } //Credits to http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/176679?help-en - n.replace("\\xC3\\x80", "A"); n.replace("\\xC3\\x81", "A"); n.replace("\\xC3\\x82", "A"); n.replace("\\xC3\\x83", "A"); - n.replace("\\xC3\\x84", "A"); n.replace("\\xC3\\x85", "A"); n.replace("\\xC3\\x86", "AE"); n.replace("\\xC3\\x87", "C"); - n.replace("\\xC3\\x88", "E"); n.replace("\\xC3\\x89", "E"); n.replace("\\xC3\\x8A", "E"); n.replace("\\xC3\\x8B", "E"); - n.replace("\\xC3\\x8C", "I"); n.replace("\\xC3\\x8D", "I"); n.replace("\\xC3\\x8E", "I"); n.replace("\\xC3\\x8F", "I"); - n.replace("\\xC3\\x90", "D"); n.replace("\\xC3\\x91", "N"); n.replace("\\xC3\\x92", "O"); n.replace("\\xC3\\x93", "O"); - n.replace("\\xC3\\x94", "O"); n.replace("\\xC3\\x95", "O"); n.replace("\\xC3\\x96", "O"); n.replace("\\xC3\\x98", "O"); - n.replace("\\xC3\\x99", "U"); n.replace("\\xC3\\x9A", "U"); n.replace("\\xC3\\x9B", "U"); n.replace("\\xC3\\x9C", "U"); - n.replace("\\xC3\\x9D", "Y"); n.replace("\\xC3\\x9E", "P"); n.replace("\\xC3\\x9F", "ss"); n.replace("\\xC9\\x99", "e"); - n.replace("\\xC3\\xA0", "a"); n.replace("\\xC3\\xA1", "a"); n.replace("\\xC3\\xA2", "a"); n.replace("\\xC3\\xA3", "a"); - n.replace("\\xC3\\xA4", "a"); n.replace("\\xC3\\xA5", "a"); n.replace("\\xC3\\xA6", "ae"); n.replace("\\xC3\\xA7", "c"); - n.replace("\\xC3\\xA8", "e"); n.replace("\\xC3\\xA9", "e"); n.replace("\\xC3\\xAA", "e"); n.replace("\\xC3\\xAB", "e"); - n.replace("\\xC3\\xAC", "i"); n.replace("\\xC3\\xAD", "i"); n.replace("\\xC3\\xAE", "i"); n.replace("\\xC3\\xAF", "i"); - n.replace("\\xC3\\xB0", "o"); n.replace("\\xC3\\xB1", "n"); n.replace("\\xC3\\xB2", "o"); n.replace("\\xC3\\xB3", "o"); - n.replace("\\xC3\\xB4", "o"); n.replace("\\xC3\\xB5", "o"); n.replace("\\xC3\\xB6", "o"); n.replace("\\xC3\\xB8", "o"); - n.replace("\\xC3\\xB9", "u"); n.replace("\\xC3\\xBA", "u"); n.replace("\\xC3\\xBB", "u"); n.replace("\\xC3\\xBC", "u"); - n.replace("\\xC3\\xBD", "y"); n.replace("\\xC3\\xBE", "p"); n.replace("\\xC3\\xBF", "y"); n.replace("\\xC7\\xBF", "o"); - n.replace("\\xC4\\x80", "A"); n.replace("\\xC4\\x81", "a"); n.replace("\\xC4\\x82", "A"); n.replace("\\xC4\\x83", "a"); - n.replace("\\xC4\\x84", "A"); n.replace("\\xC4\\x85", "a"); n.replace("\\xC4\\x86", "C"); n.replace("\\xC4\\x87", "c"); - n.replace("\\xC4\\x88", "C"); n.replace("\\xC4\\x89", "c"); n.replace("\\xC4\\x8A", "C"); n.replace("\\xC4\\x8B", "c"); - n.replace("\\xC4\\x8C", "C"); n.replace("\\xC4\\x8D", "c"); n.replace("\\xC4\\x8E", "D"); n.replace("\\xC4\\x8F", "d"); - n.replace("\\xC4\\x90", "D"); n.replace("\\xC4\\x91", "d"); n.replace("\\xC4\\x92", "E"); n.replace("\\xC4\\x93", "e"); - n.replace("\\xC4\\x94", "E"); n.replace("\\xC4\\x95", "e"); n.replace("\\xC4\\x96", "E"); n.replace("\\xC4\\x97", "e"); - n.replace("\\xC4\\x98", "E"); n.replace("\\xC4\\x99", "e"); n.replace("\\xC4\\x9A", "E"); n.replace("\\xC4\\x9B", "e"); - n.replace("\\xC4\\x9C", "G"); n.replace("\\xC4\\x9D", "g"); n.replace("\\xC4\\x9E", "G"); n.replace("\\xC4\\x9F", "g"); - n.replace("\\xC4\\xA0", "G"); n.replace("\\xC4\\xA1", "g"); n.replace("\\xC4\\xA2", "G"); n.replace("\\xC4\\xA3", "g"); - n.replace("\\xC4\\xA4", "H"); n.replace("\\xC4\\xA5", "h"); n.replace("\\xC4\\xA6", "H"); n.replace("\\xC4\\xA7", "h"); - n.replace("\\xC4\\xA8", "I"); n.replace("\\xC4\\xA9", "i"); n.replace("\\xC4\\xAA", "I"); n.replace("\\xC4\\xAB", "i"); - n.replace("\\xC4\\xAC", "I"); n.replace("\\xC4\\xAD", "i"); n.replace("\\xC4\\xAE", "I"); n.replace("\\xC4\\xAF", "i"); - n.replace("\\xC4\\xB0", "I"); n.replace("\\xC4\\xB1", "i"); n.replace("\\xC4\\xB2", "IJ"); n.replace("\\xC4\\xB3", "ij"); - n.replace("\\xC4\\xB4", "J"); n.replace("\\xC4\\xB5", "j"); n.replace("\\xC4\\xB6", "K"); n.replace("\\xC4\\xB7", "k"); - n.replace("\\xC4\\xB8", "k"); n.replace("\\xC4\\xB9", "L"); n.replace("\\xC4\\xBA", "l"); n.replace("\\xC4\\xBB", "L"); - n.replace("\\xC4\\xBC", "l"); n.replace("\\xC4\\xBD", "L"); n.replace("\\xC4\\xBE", "l"); n.replace("\\xC4\\xBF", "L"); - n.replace("\\xC5\\x80", "l"); n.replace("\\xC5\\x81", "L"); n.replace("\\xC5\\x82", "l"); n.replace("\\xC5\\x83", "N"); - n.replace("\\xC5\\x84", "n"); n.replace("\\xC5\\x85", "N"); n.replace("\\xC5\\x86", "n"); n.replace("\\xC5\\x87", "N"); - n.replace("\\xC5\\x88", "n"); n.replace("\\xC5\\x89", "n"); n.replace("\\xC5\\x8A", "N"); n.replace("\\xC5\\x8B", "n"); - n.replace("\\xC5\\x8C", "O"); n.replace("\\xC5\\x8D", "o"); n.replace("\\xC5\\x8E", "O"); n.replace("\\xC5\\x8F", "o"); - n.replace("\\xC5\\x90", "O"); n.replace("\\xC5\\x91", "o"); n.replace("\\xC5\\x92", "CE"); n.replace("\\xC5\\x93", "ce"); - n.replace("\\xC5\\x94", "R"); n.replace("\\xC5\\x95", "r"); n.replace("\\xC5\\x96", "R"); n.replace("\\xC5\\x97", "r"); - n.replace("\\xC5\\x98", "R"); n.replace("\\xC5\\x99", "r"); n.replace("\\xC5\\x9A", "S"); n.replace("\\xC5\\x9B", "s"); - n.replace("\\xC5\\x9C", "S"); n.replace("\\xC5\\x9D", "s"); n.replace("\\xC5\\x9E", "S"); n.replace("\\xC5\\x9F", "s"); - n.replace("\\xC5\\xA0", "S"); n.replace("\\xC5\\xA1", "s"); n.replace("\\xC5\\xA2", "T"); n.replace("\\xC5\\xA3", "t"); - n.replace("\\xC5\\xA4", "T"); n.replace("\\xC5\\xA5", "t"); n.replace("\\xC5\\xA6", "T"); n.replace("\\xC5\\xA7", "t"); - n.replace("\\xC5\\xA8", "U"); n.replace("\\xC5\\xA9", "u"); n.replace("\\xC5\\xAA", "U"); n.replace("\\xC5\\xAB", "u"); - n.replace("\\xC5\\xAC", "U"); n.replace("\\xC5\\xAD", "u"); n.replace("\\xC5\\xAE", "U"); n.replace("\\xC5\\xAF", "u"); - n.replace("\\xC5\\xB0", "U"); n.replace("\\xC5\\xB1", "u"); n.replace("\\xC5\\xB2", "U"); n.replace("\\xC5\\xB3", "u"); - n.replace("\\xC5\\xB4", "W"); n.replace("\\xC5\\xB5", "w"); n.replace("\\xC5\\xB6", "Y"); n.replace("\\xC5\\xB7", "y"); - n.replace("\\xC5\\xB8", "Y"); n.replace("\\xC5\\xB9", "Z"); n.replace("\\xC5\\xBA", "z"); n.replace("\\xC5\\xBB", "Z"); - n.replace("\\xC5\\xBC", "z"); n.replace("\\xC5\\xBD", "Z"); n.replace("\\xC5\\xBE", "z"); n.replace("\\xC6\\x8F", "E"); - n.replace("\\xC6\\xA0", "O"); n.replace("\\xC6\\xA1", "o"); n.replace("\\xC6\\xAF", "U"); n.replace("\\xC6\\xB0", "u"); - n.replace("\\xC7\\x8D", "A"); n.replace("\\xC7\\x8E", "a"); n.replace("\\xC7\\x8F", "I"); n.replace("\\xC7\\x93", "U"); - n.replace("\\xC7\\x90", "i"); n.replace("\\xC7\\x91", "O"); n.replace("\\xC7\\x92", "o"); n.replace("\\xC7\\x97", "U"); - n.replace("\\xC7\\x94", "u"); n.replace("\\xC7\\x95", "U"); n.replace("\\xC7\\x96", "u"); n.replace("\\xC7\\x9B", "U"); - n.replace("\\xC7\\x98", "u"); n.replace("\\xC7\\x99", "U"); n.replace("\\xC7\\x9A", "u"); n.replace("\\xC7\\xBD", "ae"); - n.replace("\\xC7\\x9C", "u"); n.replace("\\xC7\\xBB", "a"); n.replace("\\xC7\\xBC", "AE"); n.replace("\\xC7\\xBE", "O"); + n.replace("\\xC3\\x80", "A"); + n.replace("\\xC3\\x81", "A"); + n.replace("\\xC3\\x82", "A"); + n.replace("\\xC3\\x83", "A"); + n.replace("\\xC3\\x84", "A"); + n.replace("\\xC3\\x85", "A"); + n.replace("\\xC3\\x86", "AE"); + n.replace("\\xC3\\x87", "C"); + n.replace("\\xC3\\x88", "E"); + n.replace("\\xC3\\x89", "E"); + n.replace("\\xC3\\x8A", "E"); + n.replace("\\xC3\\x8B", "E"); + n.replace("\\xC3\\x8C", "I"); + n.replace("\\xC3\\x8D", "I"); + n.replace("\\xC3\\x8E", "I"); + n.replace("\\xC3\\x8F", "I"); + n.replace("\\xC3\\x90", "D"); + n.replace("\\xC3\\x91", "N"); + n.replace("\\xC3\\x92", "O"); + n.replace("\\xC3\\x93", "O"); + n.replace("\\xC3\\x94", "O"); + n.replace("\\xC3\\x95", "O"); + n.replace("\\xC3\\x96", "O"); + n.replace("\\xC3\\x98", "O"); + n.replace("\\xC3\\x99", "U"); + n.replace("\\xC3\\x9A", "U"); + n.replace("\\xC3\\x9B", "U"); + n.replace("\\xC3\\x9C", "U"); + n.replace("\\xC3\\x9D", "Y"); + n.replace("\\xC3\\x9E", "P"); + n.replace("\\xC3\\x9F", "ss"); + n.replace("\\xC9\\x99", "e"); + n.replace("\\xC3\\xA0", "a"); + n.replace("\\xC3\\xA1", "a"); + n.replace("\\xC3\\xA2", "a"); + n.replace("\\xC3\\xA3", "a"); + n.replace("\\xC3\\xA4", "a"); + n.replace("\\xC3\\xA5", "a"); + n.replace("\\xC3\\xA6", "ae"); + n.replace("\\xC3\\xA7", "c"); + n.replace("\\xC3\\xA8", "e"); + n.replace("\\xC3\\xA9", "e"); + n.replace("\\xC3\\xAA", "e"); + n.replace("\\xC3\\xAB", "e"); + n.replace("\\xC3\\xAC", "i"); + n.replace("\\xC3\\xAD", "i"); + n.replace("\\xC3\\xAE", "i"); + n.replace("\\xC3\\xAF", "i"); + n.replace("\\xC3\\xB0", "o"); + n.replace("\\xC3\\xB1", "n"); + n.replace("\\xC3\\xB2", "o"); + n.replace("\\xC3\\xB3", "o"); + n.replace("\\xC3\\xB4", "o"); + n.replace("\\xC3\\xB5", "o"); + n.replace("\\xC3\\xB6", "o"); + n.replace("\\xC3\\xB8", "o"); + n.replace("\\xC3\\xB9", "u"); + n.replace("\\xC3\\xBA", "u"); + n.replace("\\xC3\\xBB", "u"); + n.replace("\\xC3\\xBC", "u"); + n.replace("\\xC3\\xBD", "y"); + n.replace("\\xC3\\xBE", "p"); + n.replace("\\xC3\\xBF", "y"); + n.replace("\\xC7\\xBF", "o"); + n.replace("\\xC4\\x80", "A"); + n.replace("\\xC4\\x81", "a"); + n.replace("\\xC4\\x82", "A"); + n.replace("\\xC4\\x83", "a"); + n.replace("\\xC4\\x84", "A"); + n.replace("\\xC4\\x85", "a"); + n.replace("\\xC4\\x86", "C"); + n.replace("\\xC4\\x87", "c"); + n.replace("\\xC4\\x88", "C"); + n.replace("\\xC4\\x89", "c"); + n.replace("\\xC4\\x8A", "C"); + n.replace("\\xC4\\x8B", "c"); + n.replace("\\xC4\\x8C", "C"); + n.replace("\\xC4\\x8D", "c"); + n.replace("\\xC4\\x8E", "D"); + n.replace("\\xC4\\x8F", "d"); + n.replace("\\xC4\\x90", "D"); + n.replace("\\xC4\\x91", "d"); + n.replace("\\xC4\\x92", "E"); + n.replace("\\xC4\\x93", "e"); + n.replace("\\xC4\\x94", "E"); + n.replace("\\xC4\\x95", "e"); + n.replace("\\xC4\\x96", "E"); + n.replace("\\xC4\\x97", "e"); + n.replace("\\xC4\\x98", "E"); + n.replace("\\xC4\\x99", "e"); + n.replace("\\xC4\\x9A", "E"); + n.replace("\\xC4\\x9B", "e"); + n.replace("\\xC4\\x9C", "G"); + n.replace("\\xC4\\x9D", "g"); + n.replace("\\xC4\\x9E", "G"); + n.replace("\\xC4\\x9F", "g"); + n.replace("\\xC4\\xA0", "G"); + n.replace("\\xC4\\xA1", "g"); + n.replace("\\xC4\\xA2", "G"); + n.replace("\\xC4\\xA3", "g"); + n.replace("\\xC4\\xA4", "H"); + n.replace("\\xC4\\xA5", "h"); + n.replace("\\xC4\\xA6", "H"); + n.replace("\\xC4\\xA7", "h"); + n.replace("\\xC4\\xA8", "I"); + n.replace("\\xC4\\xA9", "i"); + n.replace("\\xC4\\xAA", "I"); + n.replace("\\xC4\\xAB", "i"); + n.replace("\\xC4\\xAC", "I"); + n.replace("\\xC4\\xAD", "i"); + n.replace("\\xC4\\xAE", "I"); + n.replace("\\xC4\\xAF", "i"); + n.replace("\\xC4\\xB0", "I"); + n.replace("\\xC4\\xB1", "i"); + n.replace("\\xC4\\xB2", "IJ"); + n.replace("\\xC4\\xB3", "ij"); + n.replace("\\xC4\\xB4", "J"); + n.replace("\\xC4\\xB5", "j"); + n.replace("\\xC4\\xB6", "K"); + n.replace("\\xC4\\xB7", "k"); + n.replace("\\xC4\\xB8", "k"); + n.replace("\\xC4\\xB9", "L"); + n.replace("\\xC4\\xBA", "l"); + n.replace("\\xC4\\xBB", "L"); + n.replace("\\xC4\\xBC", "l"); + n.replace("\\xC4\\xBD", "L"); + n.replace("\\xC4\\xBE", "l"); + n.replace("\\xC4\\xBF", "L"); + n.replace("\\xC5\\x80", "l"); + n.replace("\\xC5\\x81", "L"); + n.replace("\\xC5\\x82", "l"); + n.replace("\\xC5\\x83", "N"); + n.replace("\\xC5\\x84", "n"); + n.replace("\\xC5\\x85", "N"); + n.replace("\\xC5\\x86", "n"); + n.replace("\\xC5\\x87", "N"); + n.replace("\\xC5\\x88", "n"); + n.replace("\\xC5\\x89", "n"); + n.replace("\\xC5\\x8A", "N"); + n.replace("\\xC5\\x8B", "n"); + n.replace("\\xC5\\x8C", "O"); + n.replace("\\xC5\\x8D", "o"); + n.replace("\\xC5\\x8E", "O"); + n.replace("\\xC5\\x8F", "o"); + n.replace("\\xC5\\x90", "O"); + n.replace("\\xC5\\x91", "o"); + n.replace("\\xC5\\x92", "CE"); + n.replace("\\xC5\\x93", "ce"); + n.replace("\\xC5\\x94", "R"); + n.replace("\\xC5\\x95", "r"); + n.replace("\\xC5\\x96", "R"); + n.replace("\\xC5\\x97", "r"); + n.replace("\\xC5\\x98", "R"); + n.replace("\\xC5\\x99", "r"); + n.replace("\\xC5\\x9A", "S"); + n.replace("\\xC5\\x9B", "s"); + n.replace("\\xC5\\x9C", "S"); + n.replace("\\xC5\\x9D", "s"); + n.replace("\\xC5\\x9E", "S"); + n.replace("\\xC5\\x9F", "s"); + n.replace("\\xC5\\xA0", "S"); + n.replace("\\xC5\\xA1", "s"); + n.replace("\\xC5\\xA2", "T"); + n.replace("\\xC5\\xA3", "t"); + n.replace("\\xC5\\xA4", "T"); + n.replace("\\xC5\\xA5", "t"); + n.replace("\\xC5\\xA6", "T"); + n.replace("\\xC5\\xA7", "t"); + n.replace("\\xC5\\xA8", "U"); + n.replace("\\xC5\\xA9", "u"); + n.replace("\\xC5\\xAA", "U"); + n.replace("\\xC5\\xAB", "u"); + n.replace("\\xC5\\xAC", "U"); + n.replace("\\xC5\\xAD", "u"); + n.replace("\\xC5\\xAE", "U"); + n.replace("\\xC5\\xAF", "u"); + n.replace("\\xC5\\xB0", "U"); + n.replace("\\xC5\\xB1", "u"); + n.replace("\\xC5\\xB2", "U"); + n.replace("\\xC5\\xB3", "u"); + n.replace("\\xC5\\xB4", "W"); + n.replace("\\xC5\\xB5", "w"); + n.replace("\\xC5\\xB6", "Y"); + n.replace("\\xC5\\xB7", "y"); + n.replace("\\xC5\\xB8", "Y"); + n.replace("\\xC5\\xB9", "Z"); + n.replace("\\xC5\\xBA", "z"); + n.replace("\\xC5\\xBB", "Z"); + n.replace("\\xC5\\xBC", "z"); + n.replace("\\xC5\\xBD", "Z"); + n.replace("\\xC5\\xBE", "z"); + n.replace("\\xC6\\x8F", "E"); + n.replace("\\xC6\\xA0", "O"); + n.replace("\\xC6\\xA1", "o"); + n.replace("\\xC6\\xAF", "U"); + n.replace("\\xC6\\xB0", "u"); + n.replace("\\xC7\\x8D", "A"); + n.replace("\\xC7\\x8E", "a"); + n.replace("\\xC7\\x8F", "I"); + n.replace("\\xC7\\x93", "U"); + n.replace("\\xC7\\x90", "i"); + n.replace("\\xC7\\x91", "O"); + n.replace("\\xC7\\x92", "o"); + n.replace("\\xC7\\x97", "U"); + n.replace("\\xC7\\x94", "u"); + n.replace("\\xC7\\x95", "U"); + n.replace("\\xC7\\x96", "u"); + n.replace("\\xC7\\x9B", "U"); + n.replace("\\xC7\\x98", "u"); + n.replace("\\xC7\\x99", "U"); + n.replace("\\xC7\\x9A", "u"); + n.replace("\\xC7\\xBD", "ae"); + n.replace("\\xC7\\x9C", "u"); + n.replace("\\xC7\\xBB", "a"); + n.replace("\\xC7\\xBC", "AE"); + n.replace("\\xC7\\xBE", "O"); n.replace("\\xC7\\xBA", "A"); n.replace("\\xC2\\x82", ","); // High code comma @@ -118,29 +282,32 @@ QString CertificateInfoWidget::clearCertSpecialSymbols(const QString &string) QString CertificateInfoWidget::showCertInfo(const QString &string) { - if (string.isEmpty()) + if (string.isEmpty()) { return tr(""); - else return clearCertSpecialSymbols(string); + } + else { + return clearCertSpecialSymbols(string); + } } -CertificateInfoWidget::CertificateInfoWidget(const QSslCertificate &cert, QWidget *parent) +CertificateInfoWidget::CertificateInfoWidget(const QSslCertificate &cert, QWidget* parent) : QWidget(parent) , ui(new Ui::CertificateInfoWidget) { ui->setupUi(this); //Issued to - ui->issuedToCN->setText( showCertInfo(cert.subjectInfo(QSslCertificate::CommonName)) ); - ui->issuedToO->setText( showCertInfo(cert.subjectInfo(QSslCertificate::Organization)) ); - ui->issuedToOU->setText( showCertInfo(cert.subjectInfo(QSslCertificate::OrganizationalUnitName)) ); - ui->issuedToSN->setText( showCertInfo(cert.serialNumber()) ); + ui->issuedToCN->setText(showCertInfo(cert.subjectInfo(QSslCertificate::CommonName))); + ui->issuedToO->setText(showCertInfo(cert.subjectInfo(QSslCertificate::Organization))); + ui->issuedToOU->setText(showCertInfo(cert.subjectInfo(QSslCertificate::OrganizationalUnitName))); + ui->issuedToSN->setText(showCertInfo(cert.serialNumber())); //Issued By - ui->issuedByCN->setText( showCertInfo(cert.issuerInfo(QSslCertificate::CommonName)) ); - ui->issuedByO->setText( showCertInfo(cert.issuerInfo(QSslCertificate::Organization)) ); - ui->issuedByOU->setText( showCertInfo(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)) ); + ui->issuedByCN->setText(showCertInfo(cert.issuerInfo(QSslCertificate::CommonName))); + ui->issuedByO->setText(showCertInfo(cert.issuerInfo(QSslCertificate::Organization))); + ui->issuedByOU->setText(showCertInfo(cert.issuerInfo(QSslCertificate::OrganizationalUnitName))); //Validity - ui->validityIssuedOn->setText( cert.effectiveDate().toString("dddd d. MMMM yyyy") ); - ui->validityExpiresOn->setText( cert.expiryDate().toString("dddd d. MMMM yyyy") ); + ui->validityIssuedOn->setText(cert.effectiveDate().toString("dddd d. MMMM yyyy")); + ui->validityExpiresOn->setText(cert.expiryDate().toString("dddd d. MMMM yyyy")); } CertificateInfoWidget::~CertificateInfoWidget() diff --git a/src/tools/certificateinfowidget.h b/src/tools/certificateinfowidget.h index a0a6a792c..87307ae3c 100644 --- a/src/tools/certificateinfowidget.h +++ b/src/tools/certificateinfowidget.h @@ -23,8 +23,9 @@ #include #include -namespace Ui { - class CertificateInfoWidget; +namespace Ui +{ +class CertificateInfoWidget; } class CertificateInfoWidget : public QWidget @@ -32,7 +33,7 @@ class CertificateInfoWidget : public QWidget Q_OBJECT public: - explicit CertificateInfoWidget(const QSslCertificate &cert, QWidget *parent = 0); + explicit CertificateInfoWidget(const QSslCertificate &cert, QWidget* parent = 0); ~CertificateInfoWidget(); static QString showCertInfo(const QString &string); @@ -40,7 +41,7 @@ public: static QString certificateItemText(const QSslCertificate &cert); private: - Ui::CertificateInfoWidget *ui; + Ui::CertificateInfoWidget* ui; }; #endif // CERTIFICATEINFOWIDGET_H diff --git a/src/tools/clickablelabel.cpp b/src/tools/clickablelabel.cpp index 9dee2a489..3230fb86f 100644 --- a/src/tools/clickablelabel.cpp +++ b/src/tools/clickablelabel.cpp @@ -24,12 +24,14 @@ ClickableLabel::ClickableLabel(QWidget* parent) : void ClickableLabel::mousePressEvent(QMouseEvent* ev) { - if (ev->button() == Qt::LeftButton) + if (ev->button() == Qt::LeftButton) { emit clicked(ev->globalPos()); + } } void ClickableLabel::mouseDoubleClickEvent(QMouseEvent* ev) { - if (ev->button() == Qt::LeftButton) + if (ev->button() == Qt::LeftButton) { emit clicked(ev->globalPos()); + } } diff --git a/src/tools/closedtabsmanager.cpp b/src/tools/closedtabsmanager.cpp index 2301b1d88..3a5152ee1 100644 --- a/src/tools/closedtabsmanager.cpp +++ b/src/tools/closedtabsmanager.cpp @@ -19,15 +19,16 @@ #include "webview.h" #include "qwebhistory.h" -ClosedTabsManager::ClosedTabsManager(QObject *parent) : +ClosedTabsManager::ClosedTabsManager(QObject* parent) : QObject(parent) { } void ClosedTabsManager::saveView(WebView* view) { - if (view->url().isEmpty() && view->history()->items().count() == 0) + if (view->url().isEmpty() && view->history()->items().count() == 0) { return; + } Tab tab; tab.url = view->url(); @@ -41,8 +42,9 @@ void ClosedTabsManager::saveView(WebView* view) ClosedTabsManager::Tab ClosedTabsManager::getFirstClosedTab() { Tab tab; - if (m_closedTabs.count() > 0) + if (m_closedTabs.count() > 0) { tab = m_closedTabs.takeFirst(); + } return tab; } diff --git a/src/tools/closedtabsmanager.h b/src/tools/closedtabsmanager.h index b408e850d..3590ba5ea 100644 --- a/src/tools/closedtabsmanager.h +++ b/src/tools/closedtabsmanager.h @@ -32,8 +32,7 @@ public: QByteArray history; QString title; - bool operator==(const Tab &a) - { + bool operator==(const Tab &a) const { return (a.url == url) && (a.history == history); } }; diff --git a/src/tools/docktitlebarwidget.cpp b/src/tools/docktitlebarwidget.cpp index 5dc699937..f4090c7fd 100644 --- a/src/tools/docktitlebarwidget.cpp +++ b/src/tools/docktitlebarwidget.cpp @@ -22,7 +22,7 @@ DockTitleBarWidget::DockTitleBarWidget(const QString &title, QWidget* parent) : QWidget(parent) { setupUi(this); - closeButton->setIcon(QIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton).pixmap(16,16))); + closeButton->setIcon(QIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton).pixmap(16, 16))); label->setText(title); connect(closeButton, SIGNAL(clicked()), parent, SLOT(close())); } diff --git a/src/tools/followredirectreply.cpp b/src/tools/followredirectreply.cpp index b70cc53aa..0909d483d 100644 --- a/src/tools/followredirectreply.cpp +++ b/src/tools/followredirectreply.cpp @@ -13,7 +13,7 @@ void FollowRedirectReply::replyFinished() { int replyStatus = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if ( (replyStatus != 301 && replyStatus != 302) || m_redirectCount == 5) { + if ((replyStatus != 301 && replyStatus != 302) || m_redirectCount == 5) { emit finished(); return; } diff --git a/src/tools/globalfunctions.cpp b/src/tools/globalfunctions.cpp index 2f2aaef37..63a169d88 100644 --- a/src/tools/globalfunctions.cpp +++ b/src/tools/globalfunctions.cpp @@ -22,8 +22,9 @@ QByteArray qz_pixmapToByteArray(const QPixmap &pix) QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); - if (pix.save(&buffer, "PNG")) + if (pix.save(&buffer, "PNG")) { return buffer.buffer().toBase64(); + } return QByteArray(); } @@ -47,24 +48,25 @@ QByteArray qz_readAllFileContents(const QString &filename) return a; } -void qz_centerWidgetOnScreen(QWidget *w) +void qz_centerWidgetOnScreen(QWidget* w) { const QRect screen = QApplication::desktop()->screenGeometry(); const QRect &size = w->geometry(); - w->move( (screen.width()-size.width())/2, (screen.height()-size.height())/2 ); + w->move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2); } // Very, very, very simplified QDialog::adjustPosition from qdialog.cpp void qz_centerWidgetToParent(QWidget* w, QWidget* parent) { - if (!parent || !w) + if (!parent || !w) { return; + } QPoint p; parent = parent->window(); - QPoint pp = parent->mapToGlobal(QPoint(0,0)); - p = QPoint(pp.x() + parent->width()/2, pp.y() + parent->height()/ 2); - p = QPoint(p.x()-w->width()/2, p.y()-w->height()/2 - 20); + QPoint pp = parent->mapToGlobal(QPoint(0, 0)); + p = QPoint(pp.x() + parent->width() / 2, pp.y() + parent->height() / 2); + p = QPoint(p.x() - w->width() / 2, p.y() - w->height() / 2 - 20); w->move(p); } @@ -75,8 +77,9 @@ QString qz_samePartOfStrings(const QString &one, const QString &other) int maxSize = qMin(one.size(), other.size()); while (one.at(i) == other.at(i)) { i++; - if (i == maxSize) + if (i == maxSize) { break; + } } return one.left(i); } @@ -98,10 +101,12 @@ QUrl qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl) else { samePart = samePart.left(samePart.lastIndexOf("/") + 1); int slashCount = samePart.count("/") + 1; - if (samePart.startsWith("/")) + if (samePart.startsWith("/")) { slashCount--; - if (samePart.endsWith("/")) + } + if (samePart.endsWith("/")) { slashCount--; + } rUrlPath.remove(samePart); rUrlPath.prepend(QString("..""/").repeated(slashCount)); @@ -113,8 +118,9 @@ QUrl qz_makeRelativeUrl(const QUrl &baseUrl, const QUrl &rUrl) QString qz_ensureUniqueFilename(const QString &pathToFile) { - if (!QFile::exists(pathToFile)) + if (!QFile::exists(pathToFile)) { return pathToFile; + } QString tmpFileName = pathToFile; int i = 1; @@ -123,10 +129,10 @@ QString qz_ensureUniqueFilename(const QString &pathToFile) int index = tmpFileName.lastIndexOf("."); if (index == -1) { - tmpFileName.append("("+QString::number(i)+")"); + tmpFileName.append("(" + QString::number(i) + ")"); } else { - tmpFileName = tmpFileName.mid(0, index) + "("+QString::number(i)+")" + tmpFileName.mid(index); + tmpFileName = tmpFileName.mid(0, index) + "(" + QString::number(i) + ")" + tmpFileName.mid(index); } i++; } diff --git a/src/tools/htmlhighlighter.cpp b/src/tools/htmlhighlighter.cpp index fa4047a0a..5bd38a4b2 100644 --- a/src/tools/htmlhighlighter.cpp +++ b/src/tools/htmlhighlighter.cpp @@ -56,130 +56,75 @@ ****************************************************************************/ #include "htmlhighlighter.h" - HtmlHighlighter::HtmlHighlighter(QTextDocument* parent) - : QSyntaxHighlighter(parent) - { - HighlightingRule rule; +HtmlHighlighter::HtmlHighlighter(QTextDocument* parent) + : QSyntaxHighlighter(parent) +{ + HighlightingRule rule; - keywordFormat.setForeground(Qt::darkBlue); - keywordFormat.setFontWeight(QFont::Bold); - QStringList keywordPatterns; - keywordPatterns << "(||"; - foreach (const QString &pattern, keywordPatterns) { - rule.pattern = QRegExp(pattern); - rule.format = keywordFormat; - highlightingRules.append(rule); - } + // tags: + tagFormat.setForeground(Qt::darkBlue); + tagFormat.setFontWeight(QFont::Bold); + QStringList keywordPatterns; + keywordPatterns << "| )?" << ">" << "(| + tagOptionsFormat.setForeground(Qt::black); + tagOptionsFormat.setFontWeight(QFont::Bold); + rule.pattern = QRegExp("(\\S{2,20})=\""); + rule.format = tagOptionsFormat; + highlightingRules.append(rule); - singleLineCommentFormat.setForeground(Qt::red); - rule.pattern = QRegExp("//[^\n]*"); - rule.format = singleLineCommentFormat; -// highlightingRules.append(rule); + // " " strings + quotationFormat.setForeground(Qt::darkGreen); + QRegExp rx("\".*\""); + rx.setMinimal(true); + rule.pattern = rx; + rule.format = quotationFormat; + highlightingRules.append(rule); - multiLineCommentFormat.setForeground(Qt::gray); + // comments + multiLineCommentFormat.setForeground(Qt::gray); + commentStartExpression = QRegExp(""); +} - quotationFormat.setForeground(Qt::darkGreen); - QRegExp rx("\".*\""); - rx.setMinimal(true); - rule.pattern = rx; - rule.format = quotationFormat; - highlightingRules.append(rule); +void HtmlHighlighter::highlightBlock(const QString &text) +{ + foreach(const HighlightingRule & rule, highlightingRules) { + QRegExp expression(rule.pattern); + int index = expression.indexIn(text); + while (index >= 0) { + int length = expression.matchedLength(); + setFormat(index, length, rule.format); + index = expression.indexIn(text, index + length); + } + } - functionFormat.setFontWeight(QFont::Normal); - functionFormat.setForeground(Qt::red); -// rule.pattern = QRegExp("(|)"); - rx.setPattern(""); - rx.setMinimal(true); - rule.pattern = rx; - rule.format = functionFormat; -// highlightingRules.append(rule); + // Highlighting multi-line comments + setCurrentBlockState(0); - commentStartExpression = QRegExp(""); - } + int startIndex = 0; + if (previousBlockState() != 1) { + startIndex = commentStartExpression.indexIn(text); + } - void HtmlHighlighter::highlightBlock(const QString &text) - { - foreach (const HighlightingRule &rule, highlightingRules) { - QRegExp expression(rule.pattern); - int index = expression.indexIn(text); - while (index >= 0) { - int length = expression.matchedLength(); - setFormat(index, length, rule.format); - index = expression.indexIn(text, index + length); - } - } - setCurrentBlockState(0); - - int startIndex = 0; - if (previousBlockState() != 1) - startIndex = commentStartExpression.indexIn(text); - - while (startIndex >= 0) { - int endIndex = commentEndExpression.indexIn(text, startIndex); - int commentLength; - if (endIndex == -1) { - setCurrentBlockState(1); - commentLength = text.length() - startIndex; - } else { - commentLength = endIndex - startIndex - + commentEndExpression.matchedLength(); - } - setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); - } - } + while (startIndex >= 0) { + int endIndex = commentEndExpression.indexIn(text, startIndex); + int commentLength; + if (endIndex == -1) { + setCurrentBlockState(1); + commentLength = text.length() - startIndex; + } + else { + commentLength = endIndex - startIndex + + commentEndExpression.matchedLength(); + } + setFormat(startIndex, commentLength, multiLineCommentFormat); + startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); + } +} diff --git a/src/tools/htmlhighlighter.h b/src/tools/htmlhighlighter.h index f00954ad3..c0a32cd84 100644 --- a/src/tools/htmlhighlighter.h +++ b/src/tools/htmlhighlighter.h @@ -75,8 +75,7 @@ protected: void highlightBlock(const QString &text); private: - struct HighlightingRule - { + struct HighlightingRule { QRegExp pattern; QTextCharFormat format; }; @@ -85,12 +84,10 @@ private: QRegExp commentStartExpression; QRegExp commentEndExpression; - QTextCharFormat keywordFormat; + QTextCharFormat tagFormat; QTextCharFormat tagOptionsFormat; - QTextCharFormat singleLineCommentFormat; QTextCharFormat multiLineCommentFormat; QTextCharFormat quotationFormat; - QTextCharFormat functionFormat; }; #endif diff --git a/src/tools/iconfetcher.cpp b/src/tools/iconfetcher.cpp index 37e729ca5..60780f4b1 100644 --- a/src/tools/iconfetcher.cpp +++ b/src/tools/iconfetcher.cpp @@ -26,8 +26,9 @@ IconFetcher::IconFetcher(QObject* parent) void IconFetcher::fetchIcon(const QUrl &url) { - if (!m_manager) + if (!m_manager) { return; + } FollowRedirectReply* reply = new FollowRedirectReply(url, m_manager); connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded())); @@ -36,8 +37,9 @@ void IconFetcher::fetchIcon(const QUrl &url) void IconFetcher::pageDownloaded() { FollowRedirectReply* reply = qobject_cast (sender()); - if (!reply) + if (!reply) { return; + } QString html = reply->reply()->readAll(); QUrl replyUrl = reply->reply()->url(); @@ -82,8 +84,9 @@ void IconFetcher::pageDownloaded() void IconFetcher::iconDownloaded() { FollowRedirectReply* reply = qobject_cast (sender()); - if (!reply) + if (!reply) { return; + } QByteArray response = reply->reply()->readAll(); delete reply; @@ -92,8 +95,9 @@ void IconFetcher::iconDownloaded() QImage image; image.loadFromData(response); QIcon icon = QIcon(QPixmap::fromImage(image)); - if (!icon.isNull()) + if (!icon.isNull()) { emit iconFetched(icon); + } } emit finished(); diff --git a/src/tools/iconprovider.cpp b/src/tools/iconprovider.cpp index 31bcaac4f..6ab947ec0 100644 --- a/src/tools/iconprovider.cpp +++ b/src/tools/iconprovider.cpp @@ -23,7 +23,7 @@ IconProvider::IconProvider(QObject* parent) : QObject(parent) { m_timer = new QTimer(this); - m_timer->setInterval(10*1000); + m_timer->setInterval(10 * 1000); m_timer->start(); connect(m_timer, SIGNAL(timeout()), this, SLOT(saveIconsToDatabase())); @@ -35,13 +35,15 @@ void IconProvider::saveIcon(WebView* view) item.icon = view->icon(); item.url = view->url(); - if (item.icon.isNull()) + if (item.icon.isNull()) { return; + } - QPixmap iconPixmap = item.icon.pixmap(16,16); - foreach (Icon ic, m_iconBuffer) { - if (ic.url == item.url && ic.icon.pixmap(16,16).toImage() == iconPixmap.toImage()) + QPixmap iconPixmap = item.icon.pixmap(16, 16); + foreach(Icon ic, m_iconBuffer) { + if (ic.url == item.url && ic.icon.pixmap(16, 16).toImage() == iconPixmap.toImage()) { return; + } } item.icon = QIcon(iconPixmap); @@ -50,48 +52,54 @@ void IconProvider::saveIcon(WebView* view) QIcon IconProvider::iconForUrl(const QUrl &url) { - foreach (Icon ic, m_iconBuffer) { - if (ic.url == url) + foreach(Icon ic, m_iconBuffer) { + if (ic.url == url) { return ic.icon; + } } QSqlQuery query; query.prepare("SELECT icon FROM icons WHERE url=?"); query.bindValue(0, url.toEncoded(QUrl::RemoveFragment)); query.exec(); - if (query.next()) + if (query.next()) { return iconFromBase64(query.value(0).toByteArray()); + } return QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic); } QIcon IconProvider::iconForDomain(const QUrl &url) { - foreach (Icon ic, m_iconBuffer) { - if (ic.url.host() == url.host()) + foreach(Icon ic, m_iconBuffer) { + if (ic.url.host() == url.host()) { return ic.icon; + } } QSqlQuery query; query.exec("SELECT icon FROM icons WHERE url LIKE '%" + url.host() + "%'"); - if (query.next()) + if (query.next()) { return iconFromBase64(query.value(0).toByteArray()); + } return QIcon(); } void IconProvider::saveIconsToDatabase() { - foreach (Icon ic, m_iconBuffer) { + foreach(Icon ic, m_iconBuffer) { QSqlQuery query; query.prepare("SELECT id FROM icons WHERE url = ?"); query.bindValue(0, ic.url.toEncoded(QUrl::RemoveFragment)); query.exec(); - if (query.next()) + if (query.next()) { query.prepare("UPDATE icons SET icon = ? WHERE url = ?"); - else + } + else { query.prepare("INSERT INTO icons (icon, url) VALUES (?,?)"); + } query.bindValue(0, iconToBase64(ic.icon)); query.bindValue(1, ic.url.toEncoded(QUrl::RemoveFragment)); @@ -171,20 +179,27 @@ QIcon IconProvider::fromTheme(const QString &icon) #ifdef Q_WS_X11 return QIcon::fromTheme(icon); #else - if (icon == "go-home") + if (icon == "go-home") { return QIcon(":/icons/faenza/home.png"); - else if (icon == "text-plain") + } + else if (icon == "text-plain") { return QIcon(":icons/locationbar/unknownpage.png"); - else if (icon == "user-bookmarks") + } + else if (icon == "user-bookmarks") { return QIcon(":icons/faenza/user-bookmarks.png"); - else if (icon == "list-remove") + } + else if (icon == "list-remove") { return QIcon(":icons/faenza/list-remove.png"); - else if (icon == "go-next") + } + else if (icon == "go-next") { return QIcon(":icons/faenza/go-next.png"); - else if (icon == "go-previous") + } + else if (icon == "go-previous") { return QIcon(":icons/faenza/go-previous.png"); - else + } + else { return QIcon(); + } #endif } @@ -198,8 +213,9 @@ QIcon IconProvider::iconFromBase64(const QByteArray &data) in >> image; buffer.close(); - if (!image.isNull()) + if (!image.isNull()) { return image; + } return QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic); } diff --git a/src/tools/progressbar.cpp b/src/tools/progressbar.cpp index eafbb09ac..c368c98cb 100644 --- a/src/tools/progressbar.cpp +++ b/src/tools/progressbar.cpp @@ -22,21 +22,23 @@ ProgressBar::ProgressBar(QWidget* parent) , m_value(0) , m_lastPaintedValue(-1) { - setMinimumSize(QSize(130,16)); - setMaximumSize(QSize(150,16)); + setMinimumSize(QSize(130, 16)); + setMaximumSize(QSize(150, 16)); } void ProgressBar::setValue(int value) { m_value = value; - if (m_lastPaintedValue != m_value) + if (m_lastPaintedValue != m_value) { repaint(); + } } -void ProgressBar::initStyleOption(QStyleOptionProgressBar *option) +void ProgressBar::initStyleOption(QStyleOptionProgressBar* option) { - if (!option) + if (!option) { return; + } option->initFrom(this); option->minimum = 0; diff --git a/src/tools/toolbutton.cpp b/src/tools/toolbutton.cpp index db187f5f1..7142dd1fb 100644 --- a/src/tools/toolbutton.cpp +++ b/src/tools/toolbutton.cpp @@ -32,8 +32,9 @@ void ToolButton::setThemeIcon(const QString &icon) void ToolButton::setIcon(const QIcon &icon) { - if (m_usingMultiIcon) + if (m_usingMultiIcon) { setFixedSize(sizeHint()); + } m_usingMultiIcon = false; QToolButton::setIcon(icon); @@ -54,17 +55,17 @@ void ToolButton::setMultiIcon(const QPixmap &icon) int w = icon.width(); int h = icon.height(); - m_normalIcon = icon.copy(0, 0, w, h/4 ); - m_hoverIcon = icon.copy(0, h/4, w, h/4 ); - m_activeIcon = icon.copy(0, h/2, w, h/4 ); - m_disabledIcon = icon.copy(0, 3*h/4, w, h/4 ); + m_normalIcon = icon.copy(0, 0, w, h / 4); + m_hoverIcon = icon.copy(0, h / 4, w, h / 4); + m_activeIcon = icon.copy(0, h / 2, w, h / 4); + m_disabledIcon = icon.copy(0, 3 * h / 4, w, h / 4); m_usingMultiIcon = true; setFixedSize(m_normalIcon.size()); } -void ToolButton::mousePressEvent(QMouseEvent *e) +void ToolButton::mousePressEvent(QMouseEvent* e) { if (e->buttons() == Qt::MiddleButton) { emit middleMouseClicked(); @@ -80,7 +81,7 @@ void ToolButton::mousePressEvent(QMouseEvent *e) QToolButton::mousePressEvent(e); } -void ToolButton::paintEvent(QPaintEvent *e) +void ToolButton::paintEvent(QPaintEvent* e) { if (!m_usingMultiIcon) { QToolButton::paintEvent(e); diff --git a/src/tools/toolbutton.h b/src/tools/toolbutton.h index c96dcd123..2088d7f8d 100644 --- a/src/tools/toolbutton.h +++ b/src/tools/toolbutton.h @@ -37,7 +37,7 @@ class ToolButton : public QToolButton public: explicit ToolButton(QWidget* parent = 0); - void setData(const QVariant& data); + void setData(const QVariant &data); QVariant data(); void setMultiIcon(const QPixmap &icon); @@ -54,8 +54,8 @@ signals: public slots: private: - void mousePressEvent(QMouseEvent *e); - void paintEvent(QPaintEvent *e); + void mousePressEvent(QMouseEvent* e); + void paintEvent(QPaintEvent* e); bool m_usingMultiIcon; diff --git a/src/tools/treewidget.cpp b/src/tools/treewidget.cpp index 72d9b822d..738aee803 100644 --- a/src/tools/treewidget.cpp +++ b/src/tools/treewidget.cpp @@ -19,10 +19,10 @@ TreeWidget::TreeWidget(QWidget* parent) : QTreeWidget(parent) - , m_refreshAllItemsNeeded(true) - , m_showMode(ItemsCollapsed) + , m_refreshAllItemsNeeded(true) + , m_showMode(ItemsCollapsed) { - connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(sheduleRefresh())); + connect(this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(sheduleRefresh())); } void TreeWidget::clear() @@ -36,25 +36,25 @@ void TreeWidget::sheduleRefresh() m_refreshAllItemsNeeded = true; } -void TreeWidget::addTopLevelItem(QTreeWidgetItem *item) +void TreeWidget::addTopLevelItem(QTreeWidgetItem* item) { m_allTreeItems.append(item); QTreeWidget::addTopLevelItem(item); } -void TreeWidget::addTopLevelItems(const QList &items) +void TreeWidget::addTopLevelItems(const QList &items) { m_allTreeItems.append(items); QTreeWidget::addTopLevelItems(items); } -void TreeWidget::insertTopLevelItem(int index, QTreeWidgetItem *item) +void TreeWidget::insertTopLevelItem(int index, QTreeWidgetItem* item) { m_allTreeItems.append(item); QTreeWidget::insertTopLevelItem(index, item); } -void TreeWidget::insertTopLevelItems(int index, const QList &items) +void TreeWidget::insertTopLevelItems(int index, const QList &items) { m_allTreeItems.append(items); QTreeWidget::insertTopLevelItems(index, items); @@ -62,28 +62,30 @@ void TreeWidget::insertTopLevelItems(int index, const QList & void TreeWidget::mousePressEvent(QMouseEvent* event) { - if (event->modifiers() == Qt::ControlModifier) + if (event->modifiers() == Qt::ControlModifier) { emit itemControlClicked(itemAt(event->pos())); + } - if (event->buttons() == Qt::MiddleButton) + if (event->buttons() == Qt::MiddleButton) { emit itemMiddleButtonClicked(itemAt(event->pos())); + } QTreeWidget::mousePressEvent(event); } void TreeWidget::iterateAllItems(QTreeWidgetItem* parent) { - int count = parent ? parent->childCount() : topLevelItemCount(); + int count = parent ? parent->childCount() : topLevelItemCount(); - for (int i = 0; i < count; i++) - { - QTreeWidgetItem *item = parent ? parent->child(i) : topLevelItem(i); + for (int i = 0; i < count; i++) { + QTreeWidgetItem* item = parent ? parent->child(i) : topLevelItem(i); - if (item->childCount() == 0) - m_allTreeItems.append(item); + if (item->childCount() == 0) { + m_allTreeItems.append(item); + } - iterateAllItems(item); - } + iterateAllItems(item); + } } QList TreeWidget::allItems() @@ -101,29 +103,36 @@ void TreeWidget::filterString(QString string) QList _allItems = allItems(); if (string.isEmpty()) { - foreach (QTreeWidgetItem* item, _allItems) - item->setHidden(false); - for (int i = 0; i < topLevelItemCount(); i++) + foreach(QTreeWidgetItem * item, _allItems) + item->setHidden(false); + for (int i = 0; i < topLevelItemCount(); i++) { topLevelItem(i)->setHidden(false); - if (m_showMode == ItemsCollapsed) + } + if (m_showMode == ItemsCollapsed) { collapseAll(); - } else { - foreach (QTreeWidgetItem* item, _allItems) { + } + } + else { + foreach(QTreeWidgetItem * item, _allItems) { item->setHidden(!item->text(0).contains(string, Qt::CaseInsensitive)); item->setExpanded(true); } - for (int i = 0; i < topLevelItemCount(); i++) + for (int i = 0; i < topLevelItemCount(); i++) { topLevelItem(i)->setHidden(false); + } QTreeWidgetItem* firstItem = topLevelItem(0); QTreeWidgetItem* belowItem = itemBelow(firstItem); while (firstItem) { - if (!firstItem->parent() && !belowItem) + if (!firstItem->parent() && !belowItem) { firstItem->setHidden(true); - else if (!belowItem) + } + else if (!belowItem) { break; - else if (!firstItem->parent() && !belowItem->parent()) + } + else if (!firstItem->parent() && !belowItem->parent()) { firstItem->setHidden(true); + } firstItem = belowItem; belowItem = itemBelow(firstItem); } @@ -133,11 +142,13 @@ void TreeWidget::filterString(QString string) bool TreeWidget::appendToParentItem(const QString &parentText, QTreeWidgetItem* item) { QList list = findItems(parentText, Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return false; + } QTreeWidgetItem* parentItem = list.at(0); - if (!parentItem) + if (!parentItem) { return false; + } m_allTreeItems.append(item); parentItem->addChild(item); @@ -146,8 +157,9 @@ bool TreeWidget::appendToParentItem(const QString &parentText, QTreeWidgetItem* bool TreeWidget::appendToParentItem(QTreeWidgetItem* parent, QTreeWidgetItem* item) { - if (!parent || parent->treeWidget() != this) + if (!parent || parent->treeWidget() != this) { return false; + } m_allTreeItems.append(item); parent->addChild(item); @@ -157,11 +169,13 @@ bool TreeWidget::appendToParentItem(QTreeWidgetItem* parent, QTreeWidgetItem* it bool TreeWidget::prependToParentItem(const QString &parentText, QTreeWidgetItem* item) { QList list = findItems(parentText, Qt::MatchExactly); - if (list.count() == 0) + if (list.count() == 0) { return false; + } QTreeWidgetItem* parentItem = list.at(0); - if (!parentItem) + if (!parentItem) { return false; + } m_allTreeItems.append(item); parentItem->insertChild(0, item); @@ -170,18 +184,20 @@ bool TreeWidget::prependToParentItem(const QString &parentText, QTreeWidgetItem* bool TreeWidget::prependToParentItem(QTreeWidgetItem* parent, QTreeWidgetItem* item) { - if (!parent || parent->treeWidget() != this) + if (!parent || parent->treeWidget() != this) { return false; + } m_allTreeItems.append(item); parent->insertChild(0, item); return true; } -void TreeWidget::deleteItem(QTreeWidgetItem *item) +void TreeWidget::deleteItem(QTreeWidgetItem* item) { - if (m_allTreeItems.contains(item)) + if (m_allTreeItems.contains(item)) { m_allTreeItems.removeOne(item); + } delete item; } diff --git a/src/tools/treewidget.h b/src/tools/treewidget.h index 3cc2453e3..0d228940c 100644 --- a/src/tools/treewidget.h +++ b/src/tools/treewidget.h @@ -35,10 +35,10 @@ public: bool prependToParentItem(const QString &parentText, QTreeWidgetItem* item); bool prependToParentItem(QTreeWidgetItem* parent, QTreeWidgetItem* item); - void addTopLevelItem(QTreeWidgetItem *item); - void addTopLevelItems(const QList &items); - void insertTopLevelItem(int index, QTreeWidgetItem *item); - void insertTopLevelItems(int index, const QList &items); + void addTopLevelItem(QTreeWidgetItem* item); + void addTopLevelItems(const QList &items); + void insertTopLevelItem(int index, QTreeWidgetItem* item); + void insertTopLevelItems(int index, const QList &items); void deleteItem(QTreeWidgetItem* item); diff --git a/src/tools/widget.cpp b/src/tools/widget.cpp index cbe9e69cb..1a7ef415b 100644 --- a/src/tools/widget.cpp +++ b/src/tools/widget.cpp @@ -17,7 +17,7 @@ * ============================================================ */ #include "widget.h" -Widget::Widget(QWidget *parent) : +Widget::Widget(QWidget* parent) : QWidget(parent) { } diff --git a/src/tools/widget.h b/src/tools/widget.h index 011af1445..f2267b0c5 100644 --- a/src/tools/widget.h +++ b/src/tools/widget.h @@ -24,7 +24,7 @@ class Widget : public QWidget { Q_OBJECT public: - explicit Widget(QWidget *parent = 0); + explicit Widget(QWidget* parent = 0); signals: diff --git a/src/webview/searchtoolbar.cpp b/src/webview/searchtoolbar.cpp index e15e03b98..8a9cb00e0 100644 --- a/src/webview/searchtoolbar.cpp +++ b/src/webview/searchtoolbar.cpp @@ -23,10 +23,10 @@ #include "iconprovider.h" SearchToolBar::SearchToolBar(QupZilla* mainClass, QWidget* parent) - : AnimatedWidget(AnimatedWidget::Up, 300, parent) - , ui(new Ui::SearchToolbar) - , p_QupZilla(mainClass) - , m_findFlags(0) + : AnimatedWidget(AnimatedWidget::Up, 300, parent) + , ui(new Ui::SearchToolbar) + , p_QupZilla(mainClass) + , m_findFlags(0) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(widget()); @@ -56,7 +56,7 @@ QLineEdit* SearchToolBar::searchLine() void SearchToolBar::findNext() { refreshFindFlags(); - m_findFlags+=4; + m_findFlags += 4; searchText(ui->lineEdit->text()); } @@ -64,7 +64,7 @@ void SearchToolBar::findNext() void SearchToolBar::findPrevious() { refreshFindFlags(); - m_findFlags+=5; + m_findFlags += 5; searchText(ui->lineEdit->text()); } @@ -72,15 +72,16 @@ void SearchToolBar::refreshFindFlags() { m_findFlags = 0; if (ui->highligh->isChecked()) { - m_findFlags+=8; + m_findFlags += 8; searchText(ui->lineEdit->text()); - }else{ - m_findFlags+=8; + } + else { + m_findFlags += 8; searchText(""); - m_findFlags-=8; + m_findFlags -= 8; } if (ui->caseSensitive->isChecked()) { - m_findFlags+=2; + m_findFlags += 2; searchText(ui->lineEdit->text()); } } @@ -88,13 +89,16 @@ void SearchToolBar::refreshFindFlags() void SearchToolBar::searchText(const QString &text) { bool found = p_QupZilla->weView()->findText(text, QFlags(m_findFlags)); - if (text.isEmpty()) + if (text.isEmpty()) { found = true; + } - if (!found) + if (!found) { ui->results->setText(tr("No results found.")); - else + } + else { ui->results->clear(); + } ui->lineEdit->setProperty("notfound", !found); diff --git a/src/webview/searchtoolbar.h b/src/webview/searchtoolbar.h index 727bbf7bd..a4f51d80d 100644 --- a/src/webview/searchtoolbar.h +++ b/src/webview/searchtoolbar.h @@ -26,8 +26,9 @@ #include #include "animatedwidget.h" -namespace Ui { - class SearchToolbar; +namespace Ui +{ +class SearchToolbar; } class QupZilla; diff --git a/src/webview/siteinfo.cpp b/src/webview/siteinfo.cpp index d287a1d2d..d6017c0d6 100644 --- a/src/webview/siteinfo.cpp +++ b/src/webview/siteinfo.cpp @@ -27,9 +27,12 @@ QString SiteInfo::showCertInfo(const QString &string) { - if (string.isEmpty()) + if (string.isEmpty()) { return tr(""); - else return string; + } + else { + return string; + } } SiteInfo::SiteInfo(QupZilla* mainClass, QWidget* parent) @@ -47,52 +50,59 @@ SiteInfo::SiteInfo(QupZilla* mainClass, QWidget* parent) //GENERAL ui->heading->setText(QString("%1:").arg(title)); ui->siteAddress->setText(frame->baseUrl().toString()); - ui->sizeLabel->setText( DownloadItem::fileSizeToString(view->webPage()->totalBytes()) ); + ui->sizeLabel->setText(DownloadItem::fileSizeToString(view->webPage()->totalBytes())); QString encoding; //Meta QWebElementCollection meta = frame->findAllElements("meta"); - for (int i = 0; itreeImages); item->setText(0, alt); item->setText(1, src); @@ -106,23 +116,25 @@ SiteInfo::SiteInfo(QupZilla* mainClass, QWidget* parent) m_certWidget = new CertificateInfoWidget(cert); ui->certFrame->addWidget(m_certWidget); - } else { + } + else { ui->securityLabel->setText(tr("Connection Not Encrypted.")); ui->certLabel->setText(tr("Your connection to this page is not secured!")); } - connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*))); + connect(ui->listWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*))); connect(ui->secDetailsButton, SIGNAL(clicked()), this, SLOT(securityDetailsClicked())); - connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*))); + connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*))); ui->treeImages->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->treeImages, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(imagesCustomContextMenuRequested(const QPoint&))); + connect(ui->treeImages, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(imagesCustomContextMenuRequested(const QPoint &))); } -void SiteInfo::imagesCustomContextMenuRequested(const QPoint& p) +void SiteInfo::imagesCustomContextMenuRequested(const QPoint &p) { QTreeWidgetItem* item = ui->treeImages->itemAt(p); - if (!item) + if (!item) { return; + } QMenu menu; menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Image Location"), this, SLOT(copyActionData()))->setData(item->text(1)); @@ -143,8 +155,9 @@ void SiteInfo::downloadImage() { if (QAction* action = qobject_cast(sender())) { QTreeWidgetItem* item = ui->treeImages->topLevelItem(action->data().toInt()); - if (!item) + if (!item) { return; + } if (m_activePixmap.isNull()) { QMessageBox::warning(this, tr("Error!"), tr("This preview is not available!")); @@ -154,8 +167,9 @@ void SiteInfo::downloadImage() QString imageFileName = qz_getFileNameFromUrl(QUrl(item->text(1))); QString filePath = QFileDialog::getSaveFileName(this, tr("Save image..."), QDir::homePath() + "/" + imageFileName); - if (filePath.isEmpty()) + if (filePath.isEmpty()) { return; + } if (!m_activePixmap.save(filePath)) { QMessageBox::critical(this, tr("Error!"), tr("Cannot write to file!")); @@ -164,10 +178,11 @@ void SiteInfo::downloadImage() } } -void SiteInfo::showImagePreview(QTreeWidgetItem *item) +void SiteInfo::showImagePreview(QTreeWidgetItem* item) { - if (!item) + if (!item) { return; + } QUrl imageUrl = item->text(1); QGraphicsScene* scene = new QGraphicsScene(ui->mediaPreview); @@ -183,16 +198,20 @@ void SiteInfo::showImagePreview(QTreeWidgetItem *item) } QIODevice* cacheData = mApp->networkCache()->data(imageUrl); - if (!cacheData) + if (!cacheData) { m_activePixmap = QPixmap(); - else + } + else { m_activePixmap.loadFromData(cacheData->readAll()); + } } - if (m_activePixmap.isNull()) + if (m_activePixmap.isNull()) { scene->addText(tr("Preview not available")); - else + } + else { scene->addPixmap(m_activePixmap); + } ui->mediaPreview->setScene(scene); } @@ -202,10 +221,11 @@ void SiteInfo::securityDetailsClicked() ui->listWidget->setCurrentRow(2); } -void SiteInfo::itemChanged(QListWidgetItem *item) +void SiteInfo::itemChanged(QListWidgetItem* item) { - if (!item) + if (!item) { return; + } int index = item->whatsThis().toInt(); ui->stackedWidget->setCurrentIndex(index); } @@ -213,6 +233,7 @@ void SiteInfo::itemChanged(QListWidgetItem *item) SiteInfo::~SiteInfo() { delete ui; - if (m_certWidget) + if (m_certWidget) { delete m_certWidget; + } } diff --git a/src/webview/siteinfo.h b/src/webview/siteinfo.h index 82cd3cf47..eeef3a7f7 100644 --- a/src/webview/siteinfo.h +++ b/src/webview/siteinfo.h @@ -23,8 +23,9 @@ #include #include -namespace Ui { - class SiteInfo; +namespace Ui +{ +class SiteInfo; } class QupZilla; @@ -44,7 +45,7 @@ private slots: void showImagePreview(QTreeWidgetItem* item); void securityDetailsClicked(); - void imagesCustomContextMenuRequested(const QPoint& p); + void imagesCustomContextMenuRequested(const QPoint &p); void copyActionData(); void downloadImage(); diff --git a/src/webview/siteinfowidget.cpp b/src/webview/siteinfowidget.cpp index 305ded60c..0c6016005 100644 --- a/src/webview/siteinfowidget.cpp +++ b/src/webview/siteinfowidget.cpp @@ -22,13 +22,14 @@ SiteInfoWidget::SiteInfoWidget(QupZilla* mainClass, QWidget* parent) : QMenu(parent) - ,ui(new Ui::SiteInfoWidget) - ,p_QupZilla(mainClass) + , ui(new Ui::SiteInfoWidget) + , p_QupZilla(mainClass) { WebView* view = p_QupZilla->weView(); QUrl url = view->url(); - if (url.isEmpty() || url.scheme() == "qupzilla") + if (url.isEmpty() || url.scheme() == "qupzilla") { return; + } this->setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); @@ -46,24 +47,29 @@ SiteInfoWidget::SiteInfoWidget(QupZilla* mainClass, QWidget* parent) : QSqlQuery query; QString host = url.host(); - query.exec("SELECT sum(count) FROM history WHERE url LIKE '"+scheme+"://"+host+"%' "); + query.exec("SELECT sum(count) FROM history WHERE url LIKE '" + scheme + "://" + host + "%' "); if (query.next()) { int count = query.value(0).toInt(); if (count > 3) { ui->historyLabel->setText(tr("This is your %1. visit of this site.").arg(count)); ui->historyIcon->setPixmap(QPixmap(":/icons/locationbar/accept.png")); - } else if (count == 0) { - ui->historyLabel->setText(tr("You have never visited this site before.")); - ui->historyIcon->setPixmap(QPixmap(":/icons/locationbar/warning.png")); - } else { + } + else if (count == 0) { + ui->historyLabel->setText(tr("You have never visited this site before.")); + ui->historyIcon->setPixmap(QPixmap(":/icons/locationbar/warning.png")); + } + else { ui->historyIcon->setPixmap(QPixmap(":/icons/locationbar/warning.png")); QString text; - if (count == 1) + if (count == 1) { text = tr("first"); - else if (count == 2) + } + else if (count == 2) { text = tr("second"); - else if (count == 3) + } + else if (count == 3) { text = tr("third"); + } ui->historyLabel->setText(tr("This is your %1. visit of this site.").arg(text)); } } diff --git a/src/webview/siteinfowidget.h b/src/webview/siteinfowidget.h index 19d1f9f21..26925042b 100644 --- a/src/webview/siteinfowidget.h +++ b/src/webview/siteinfowidget.h @@ -21,8 +21,9 @@ #include #include -namespace Ui { - class SiteInfoWidget; +namespace Ui +{ +class SiteInfoWidget; } class QupZilla; diff --git a/src/webview/tabbar.cpp b/src/webview/tabbar.cpp index 8108664b5..dac453a3b 100644 --- a/src/webview/tabbar.cpp +++ b/src/webview/tabbar.cpp @@ -55,22 +55,25 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget) void TabBar::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Browser-Tabs-Settings"); - setMovable( settings.value("makeTabsMovable",true).toBool() ); - if (settings.value("ActivateLastTabWhenClosingActual", false).toBool()) + setMovable(settings.value("makeTabsMovable", true).toBool()); + if (settings.value("ActivateLastTabWhenClosingActual", false).toBool()) { setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); + } settings.endGroup(); } void TabBar::updateVisibilityWithFullscreen(bool visible) { - if (visible) + if (visible) { emit showButtons(); - else + } + else { emit hideButtons(); + } QTabBar::setVisible(visible); } @@ -78,8 +81,9 @@ void TabBar::updateVisibilityWithFullscreen(bool visible) void TabBar::setVisible(bool visible) { if (visible) { - if (p_QupZilla->isFullScreen()) + if (p_QupZilla->isFullScreen()) { return; + } emit showButtons(); } @@ -96,16 +100,19 @@ void TabBar::contextMenuRequested(const QPoint &position) m_clickedTab = index; QMenu menu; - menu.addAction(QIcon(":/icons/menu/popup.png"),tr("&New tab"), p_QupZilla, SLOT(addTab())); + menu.addAction(QIcon(":/icons/menu/popup.png"), tr("&New tab"), p_QupZilla, SLOT(addTab())); menu.addSeparator(); - if (index!=-1) { + if (index != -1) { WebTab* webTab = qobject_cast(m_tabWidget->widget(m_clickedTab)); - if (!webTab) + if (!webTab) { return; - if (p_QupZilla->weView(m_clickedTab)->isLoading()) + } + if (p_QupZilla->weView(m_clickedTab)->isLoading()) { menu.addAction(IconProvider::standardIcon(QStyle::SP_BrowserStop), tr("&Stop Tab"), this, SLOT(stopTab())); - else + } + else { menu.addAction(IconProvider::standardIcon(QStyle::SP_BrowserReload), tr("&Reload Tab"), this, SLOT(reloadTab())); + } menu.addAction(tr("&Duplicate Tab"), this, SLOT(duplicateTab())); menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); @@ -119,19 +126,20 @@ void TabBar::contextMenuRequested(const QPoint &position) menu.addAction(action); menu.addSeparator(); menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); - menu.addAction(QIcon::fromTheme("window-close"),tr("Cl&ose"), this, SLOT(closeTab())); + menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab())); menu.addSeparator(); - } else { + } + else { menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("Bookmark &All Ta&bs"), p_QupZilla, SLOT(bookmarkAllTabs())); menu.addSeparator(); - QAction* action = menu.addAction(QIcon::fromTheme("user-trash"),tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab())); + QAction* action = menu.addAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), m_tabWidget, SLOT(restoreClosedTab())); m_tabWidget->canRestoreTab() ? action->setEnabled(true) : action->setEnabled(false); } //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu.exec(p); p_QupZilla->actionRestoreTab()->setEnabled(true); } @@ -145,7 +153,8 @@ QSize TabBar::tabSizeHint(int index) const if (webTab && webTab->isPinned()) { size.setWidth(PINNED_TAB_WIDTH); - } else { + } + else { int availableWidth = width() - (PINNED_TAB_WIDTH * m_pinnedTabsCount) - m_tabWidget->buttonListTabs()->width() - m_tabWidget->buttonAddTab()->width(); int normalTabsCount = count() - m_pinnedTabsCount; if (availableWidth >= MAXIMUM_TAB_WIDTH * normalTabsCount) { @@ -174,8 +183,9 @@ QSize TabBar::tabSizeHint(int index) const if (index == count() - 1) { int xForAddTabButton = (PINNED_TAB_WIDTH * m_pinnedTabsCount) + (count() - m_pinnedTabsCount) * (m_normalTabWidth); - if (m_adjustingLastTab) - xForAddTabButton += m_lastTabWidth - m_normalTabWidth; + if (m_adjustingLastTab) { + xForAddTabButton += m_lastTabWidth - m_normalTabWidth; + } emit tabBar->moveAddTabButton(xForAddTabButton); } @@ -197,21 +207,24 @@ void TabBar::tabInserted(int index) // connect(closeButton, SIGNAL(clicked()), this, SLOT(closeCurrentTab())); // setTabButton(index, QTabBar::RightSide, closeButton); QAbstractButton* button = (QAbstractButton*)tabButton(index, QTabBar::RightSide); - if (!button) + if (!button) { return; - button->resize(17,17); + } + button->resize(17, 17); } void TabBar::showCloseButton(int index) { WebTab* webTab = qobject_cast(m_tabWidget->widget(index)); - if (webTab && webTab->isPinned()) + if (webTab && webTab->isPinned()) { return; + } CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide); - if (!button) + if (!button) { return; + } button->show(); } @@ -219,8 +232,9 @@ void TabBar::showCloseButton(int index) void TabBar::hideCloseButton(int index) { CloseButton* button = (CloseButton*)tabButton(index, QTabBar::RightSide); - if (!button) + if (!button) { return; + } button->hide(); } #endif @@ -228,21 +242,25 @@ void TabBar::hideCloseButton(int index) void TabBar::updateCloseButton(int index) { QAbstractButton* button = qobject_cast(tabButton(index, QTabBar::RightSide)); - if (!button) + if (!button) { return; + } WebTab* webTab = qobject_cast(m_tabWidget->widget(index)); - if (webTab && webTab->isPinned()) + if (webTab && webTab->isPinned()) { button->hide(); - else + } + else { button->show(); + } } void TabBar::closeCurrentTab() { int id = currentIndex(); - if (id < 0) + if (id < 0) { return; + } m_tabWidget->closeTab(id); } @@ -255,15 +273,18 @@ void TabBar::bookmarkTab() void TabBar::pinTab() { WebTab* webTab = qobject_cast(m_tabWidget->widget(m_clickedTab)); - if (!webTab) + if (!webTab) { return; + } webTab->pinTab(m_clickedTab); - if (webTab->isPinned()) + if (webTab->isPinned()) { m_pinnedTabsCount++; - else + } + else { m_pinnedTabsCount--; + } // Adjust add tab button in proper position tabSizeHint(count() - 1); @@ -292,7 +313,7 @@ int TabBar::normalTabsCount() void TabBar::mouseDoubleClickEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton && tabAt(event->pos()) == -1) { - m_tabWidget->addView(QUrl(),tr("New tab"), TabWidget::NewTab, true); + m_tabWidget->addView(QUrl(), tr("New tab"), TabWidget::NewTab, true); return; } QTabBar::mouseDoubleClickEvent(event); diff --git a/src/webview/tabwidget.cpp b/src/webview/tabwidget.cpp index 9410c3431..1c910fd61 100644 --- a/src/webview/tabwidget.cpp +++ b/src/webview/tabwidget.cpp @@ -32,16 +32,14 @@ class NewTabButton : public QToolButton { public: - explicit NewTabButton(QWidget* parent ) : QToolButton(parent) - { + explicit NewTabButton(QWidget* parent) : QToolButton(parent) { #ifndef Q_WS_WIN setIcon(QIcon::fromTheme("list-add")); - setIconSize(QSize(16,16)); + setIconSize(QSize(16, 16)); setAutoRaise(true); #endif } - QSize sizeHint() const - { + QSize sizeHint() const { QSize siz = QToolButton::sizeHint(); siz.setWidth(26); return siz; @@ -49,8 +47,7 @@ public: #ifdef Q_WS_WIN private: - void paintEvent(QPaintEvent*) - { + void paintEvent(QPaintEvent*) { QPainter p(this); QStyleOptionTabV3 opt; opt.init(this); @@ -58,8 +55,8 @@ private: QPixmap pix(":/icons/other/list-add.png"); QRect r = this->rect(); - r.setHeight(r.height()+3); - r.setWidth(r.width()+3); + r.setHeight(r.height() + 3); + r.setWidth(r.width() + 3); style()->drawItemPixmap(&p, r, Qt::AlignCenter, pix); } #endif @@ -68,29 +65,29 @@ private: class TabListButton : public QToolButton { public: - explicit TabListButton(QWidget* parent ) : QToolButton(parent) - { + explicit TabListButton(QWidget* parent) : QToolButton(parent) { } - QSize sizeHint() const - { + QSize sizeHint() const { QSize siz = QToolButton::sizeHint(); siz.setWidth(20); return siz; } private: - void paintEvent(QPaintEvent*) - { + void paintEvent(QPaintEvent*) { QPainter p(this); QStyleOptionToolButton opt; opt.init(this); - if (isDown()) + if (isDown()) { opt.state |= QStyle::State_On; - if (opt.state & QStyle::State_MouseOver) + } + if (opt.state & QStyle::State_MouseOver) { opt.activeSubControls = QStyle::SC_ToolButton; - if (!isChecked() && !isDown()) - opt.state |= QStyle::State_Raised; + } + if (!isChecked() && !isDown()) { + opt.state |= QStyle::State_Raised; + } opt.state |= QStyle::State_AutoRaise; style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this); @@ -98,12 +95,12 @@ private: }; TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) - : QTabWidget(parent) - , p_QupZilla(mainClass) - , m_lastTabIndex(0) - , m_isClosingToLastTabIndex(false) - , m_closedTabsManager(new ClosedTabsManager(this)) - , m_locationBars(new QStackedWidget()) + : QTabWidget(parent) + , p_QupZilla(mainClass) + , m_lastTabIndex(0) + , m_isClosingToLastTabIndex(false) + , m_closedTabsManager(new ClosedTabsManager(this)) + , m_locationBars(new QStackedWidget()) { setObjectName("tabwidget"); m_tabBar = new TabBar(p_QupZilla, this); @@ -120,7 +117,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int))); connect(m_tabBar, SIGNAL(closeAllButCurrent(int)), this, SLOT(closeAllButCurrent(int))); connect(m_tabBar, SIGNAL(duplicateTab(int)), this, SLOT(duplicateTab(int))); - connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int))); + connect(m_tabBar, SIGNAL(tabMoved(int, int)), this, SLOT(tabMoved(int, int))); connect(m_tabBar, SIGNAL(moveAddTabButton(int)), this, SLOT(moveAddTabButton(int))); connect(m_tabBar, SIGNAL(showButtons()), this, SLOT(showButtons())); @@ -147,19 +144,19 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) void TabWidget::loadSettings() { - QSettings settings(mApp->getActiveProfilPath()+"settings.ini", QSettings::IniFormat); + QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat); settings.beginGroup("Browser-Tabs-Settings"); m_hideCloseButtonWithOneTab = settings.value("hideCloseButtonWithOneTab", false).toBool(); - m_hideTabBarWithOneTab = settings.value("hideTabsWithOneTab",false).toBool(); + m_hideTabBarWithOneTab = settings.value("hideTabsWithOneTab", false).toBool(); settings.endGroup(); settings.beginGroup("Web-URL-Settings"); - m_urlOnNewTab = settings.value("newTabUrl","").toUrl(); + m_urlOnNewTab = settings.value("newTabUrl", "").toUrl(); settings.endGroup(); m_tabBar->loadSettings(); } -void TabWidget::resizeEvent(QResizeEvent *e) +void TabWidget::resizeEvent(QResizeEvent* e) { QPoint posit; posit.setY(0); @@ -183,7 +180,7 @@ void TabWidget::hideButtons() void TabWidget::moveAddTabButton(int posX) { - int posY = ( m_tabBar->height() - m_buttonAddTab->height() ) / 2; + int posY = (m_tabBar->height() - m_buttonAddTab->height()) / 2; m_buttonAddTab->move(posX, posY); } @@ -191,29 +188,35 @@ void TabWidget::aboutToShowTabsMenu() { m_menuTabs->clear(); WebView* actView = weView(); - if (!actView) + if (!actView) { return; - for (int i = 0; isetIcon(QIcon(":/icons/menu/dot.png")); - else + } + else { action->setIcon(_iconForUrl(view->url())); + } if (view->title().isEmpty()) { if (view->isLoading()) { action->setText(tr("Loading...")); action->setIcon(QIcon(":/icons/other/progress.gif")); - }else + } + else { action->setText(tr("No Named Page")); + } } - else{ + else { QString title = view->title(); - if (title.length()>40) { + if (title.length() > 40) { title.truncate(40); - title+=".."; + title += ".."; } action->setText(title); } @@ -237,8 +240,9 @@ int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool se { m_lastTabIndex = currentIndex(); - if (url.isEmpty()) + if (url.isEmpty()) { url = m_urlOnNewTab; + } LocationBar* locBar = new LocationBar(p_QupZilla); m_locationBars->addWidget(locBar); @@ -248,28 +252,37 @@ int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool se setTabText(index, title); webView->animationLoading(index, true)->movie()->stop(); - webView->animationLoading(index, false)->setPixmap(_iconForUrl(url).pixmap(16,16)); + webView->animationLoading(index, false)->setPixmap(_iconForUrl(url).pixmap(16, 16)); - if (openIn == TabWidget::NewSelectedTab) + if (openIn == TabWidget::NewSelectedTab) { setCurrentIndex(index); + } - if (count() == 1 && m_hideTabBarWithOneTab) + if (count() == 1 && m_hideTabBarWithOneTab) { tabBar()->setVisible(false); - else tabBar()->setVisible(true); + } + else { + tabBar()->setVisible(true); + } - if (count() == 1 && m_hideCloseButtonWithOneTab) + if (count() == 1 && m_hideCloseButtonWithOneTab) { tabBar()->setTabsClosable(false); - else tabBar()->setTabsClosable(true); + } + else { + tabBar()->setTabsClosable(true); + } connect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); connect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged())); connect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString))); - if (url.isValid()) + if (url.isValid()) { webView->load(url); + } - if (selectLine) + if (selectLine) { p_QupZilla->locationBar()->setFocus(); + } if (openIn == NewSelectedTab) { m_isClosingToLastTabIndex = true; @@ -279,14 +292,15 @@ int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool se return index; } -void TabWidget::setTabText(int index, const QString& text) +void TabWidget::setTabText(int index, const QString &text) { QString newtext = text; newtext.remove("&"); // Avoid Alt+letter shortcuts - if (WebTab* webTab = qobject_cast(p_QupZilla->tabWidget()->widget(index)) ) { - if (webTab->isPinned()) + if (WebTab* webTab = qobject_cast(p_QupZilla->tabWidget()->widget(index))) { + if (webTab->isPinned()) { newtext = ""; + } } QTabWidget::setTabText(index, newtext); @@ -294,17 +308,21 @@ void TabWidget::setTabText(int index, const QString& text) void TabWidget::closeTab(int index) { - if (count() == 1) + if (count() == 1) { return; - if (index == -1) + } + if (index == -1) { index = currentIndex(); + } WebView* webView = weView(index); - if (!webView) + if (!webView) { return; + } - if (webView->webTab()->isPinned()) + if (webView->webTab()->isPinned()) { emit pinnedTabClosed(); + } m_locationBars->removeWidget(webView->webTab()->locationBar()); disconnect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); @@ -313,15 +331,18 @@ void TabWidget::closeTab(int index) //Save last tab url and history m_closedTabsManager->saveView(webView); - if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) + if (m_isClosingToLastTabIndex && m_lastTabIndex < count() && index == currentIndex()) { setCurrentIndex(m_lastTabIndex); + } delete widget(index); - if (count() == 1 && m_hideCloseButtonWithOneTab) + if (count() == 1 && m_hideCloseButtonWithOneTab) { tabBar()->setTabsClosable(false); - if (count() == 1 && m_hideTabBarWithOneTab) + } + if (count() == 1 && m_hideTabBarWithOneTab) { tabBar()->setVisible(false); + } // if (count() < 1) // p_QupZilla->close(); @@ -336,22 +357,25 @@ void TabWidget::tabMoved(int before, int after) void TabWidget::currentTabChanged(int index) { - if (index < 0) + if (index < 0) { return; + } m_isClosingToLastTabIndex = false; WebView* webView = weView(); LocationBar* locBar = webView->webTab()->locationBar(); QString title = webView->title(); - if (title.isEmpty()) + if (title.isEmpty()) { title = tr("No Named Page"); + } p_QupZilla->setWindowTitle(title + " - QupZilla"); // p_QupZilla->locationBar()->showUrl(weView()->url(),false); - if (m_locationBars->indexOf(locBar) != -1) + if (m_locationBars->indexOf(locBar) != -1) { m_locationBars->setCurrentWidget(locBar); + } p_QupZilla->ipLabel()->setText(webView->getIp()); if (webView->isLoading()) { @@ -359,7 +383,8 @@ void TabWidget::currentTabChanged(int index) p_QupZilla->progressBar()->setVisible(true); p_QupZilla->progressBar()->setValue(webView->getLoading()); p_QupZilla->navigationBar()->showStopButton(); - } else { + } + else { p_QupZilla->progressBar()->setVisible(false); p_QupZilla->navigationBar()->showReloadButton(); p_QupZilla->ipLabel()->show(); @@ -372,7 +397,7 @@ void TabWidget::currentTabChanged(int index) void TabWidget::reloadAllTabs() { - for (int i = 0; i(widget(index)); - foreach (WebTab* tab, allTabs(false)) { - if (akt == widget(tab->view()->tabIndex())) + foreach(WebTab * tab, allTabs(false)) { + if (akt == widget(tab->view()->tabIndex())) { continue; + } closeTab(tab->view()->tabIndex()); } } @@ -402,16 +428,19 @@ void TabWidget::duplicateTab(int index) void TabWidget::restoreClosedTab() { - if (!m_closedTabsManager->isClosedTabAvailable()) + if (!m_closedTabsManager->isClosedTabAvailable()) { return; + } ClosedTabsManager::Tab tab; QAction* action = qobject_cast(sender()); - if (action && action->data().toInt() != 0) + if (action && action->data().toInt() != 0) { tab = m_closedTabsManager->getTabAt(action->data().toInt()); - else + } + else { tab = m_closedTabsManager->getFirstClosedTab(); + } int index = addView(QUrl(), tab.title); QDataStream historyStream(tab.history); historyStream >> *weView(index)->history(); @@ -421,11 +450,12 @@ void TabWidget::restoreClosedTab() void TabWidget::restoreAllClosedTabs() { - if (!m_closedTabsManager->isClosedTabAvailable()) + if (!m_closedTabsManager->isClosedTabAvailable()) { return; + } QList closedTabs = m_closedTabsManager->allClosedTabs(); - foreach (ClosedTabsManager::Tab tab, closedTabs) { + foreach(ClosedTabsManager::Tab tab, closedTabs) { int index = addView(QUrl(), tab.title); QDataStream historyStream(tab.history); historyStream >> *weView(index)->history(); @@ -450,8 +480,9 @@ QList TabWidget::allTabs(bool withPinned) QList allTabs; for (int i = 0; i < count(); i++) { WebTab* tab = qobject_cast(widget(i)); - if (!tab || (!withPinned && tab->isPinned()) ) + if (!tab || (!withPinned && tab->isPinned())) { continue; + } allTabs.append(tab); } return allTabs; @@ -467,8 +498,9 @@ void TabWidget::savePinnedTabs() for (int i = 0; i < count(); ++i) { if (WebView* tab = weView(i)) { WebTab* webTab = qobject_cast(widget(i)); - if (!webTab || !webTab->isPinned()) + if (!webTab || !webTab->isPinned()) { continue; + } tabs.append(QString::fromUtf8(tab->url().toEncoded())); if (tab->history()->count() != 0) { @@ -476,17 +508,19 @@ void TabWidget::savePinnedTabs() QDataStream tabHistoryStream(&tabHistory, QIODevice::WriteOnly); tabHistoryStream << *tab->history(); tabsHistory.append(tabHistory); - } else { + } + else { tabsHistory << QByteArray(); } - } else { + } + else { tabs.append(QString::null); tabsHistory.append(QByteArray()); } } stream << tabs; stream << tabsHistory; - QFile file(mApp->getActiveProfilPath()+"pinnedtabs.dat"); + QFile file(mApp->getActiveProfilPath() + "pinnedtabs.dat"); file.open(QIODevice::WriteOnly); file.write(data); file.close(); @@ -494,14 +528,15 @@ void TabWidget::savePinnedTabs() void TabWidget::restorePinnedTabs() { - QFile file(mApp->getActiveProfilPath()+"pinnedtabs.dat"); + QFile file(mApp->getActiveProfilPath() + "pinnedtabs.dat"); file.open(QIODevice::ReadOnly); QByteArray sd = file.readAll(); file.close(); QDataStream stream(&sd, QIODevice::ReadOnly); - if (stream.atEnd()) + if (stream.atEnd()) { return; + } QStringList pinnedTabs; stream >> pinnedTabs; @@ -514,11 +549,12 @@ void TabWidget::restorePinnedTabs() QByteArray historyState = tabHistory.value(i); int addedIndex; if (!historyState.isEmpty()) { - addedIndex= addView(QUrl()); + addedIndex = addView(QUrl()); QDataStream historyStream(historyState); historyStream >> *weView(addedIndex)->history(); weView(addedIndex)->load(url); - } else { + } + else { addedIndex = addView(url); } WebTab* webTab = qobject_cast(widget(addedIndex)); @@ -542,8 +578,9 @@ QByteArray TabWidget::saveState() for (int i = 0; i < count(); ++i) { if (WebView* tab = weView(i)) { WebTab* webTab = qobject_cast(widget(i)); - if (webTab && webTab->isPinned()) + if (webTab && webTab->isPinned()) { continue; + } tabs.append(QString::fromUtf8(tab->url().toEncoded())); if (tab->history()->count() != 0) { @@ -551,10 +588,12 @@ QByteArray TabWidget::saveState() QDataStream tabHistoryStream(&tabHistory, QIODevice::WriteOnly); tabHistoryStream << *tab->history(); tabsHistory.append(tabHistory); - } else { + } + else { tabsHistory << QByteArray(); } - } else { + } + else { tabs.append(QString::null); tabsHistory.append(QByteArray()); } @@ -570,8 +609,9 @@ bool TabWidget::restoreState(const QByteArray &state) { QByteArray sd = state; QDataStream stream(&sd, QIODevice::ReadOnly); - if (stream.atEnd()) + if (stream.atEnd()) { return false; + } QStringList openTabs; int currentTab; @@ -589,7 +629,8 @@ bool TabWidget::restoreState(const QByteArray &state) QDataStream historyStream(historyState); historyStream >> *weView(index)->history(); weView(index)->load(url); - } else { + } + else { addView(url); } } diff --git a/src/webview/tabwidget.h b/src/webview/tabwidget.h index 28c6d4a99..eba44ca6e 100644 --- a/src/webview/tabwidget.h +++ b/src/webview/tabwidget.h @@ -44,7 +44,7 @@ class TabWidget : public QTabWidget public: explicit TabWidget(QupZilla* mainclass, QWidget* parent = 0); ~TabWidget(); - enum OpenUrlIn{ CurrentTab, NewSelectedTab, NewNotSelectedTab, NewTab = NewSelectedTab }; + enum OpenUrlIn { CurrentTab, NewSelectedTab, NewNotSelectedTab, NewTab = NewSelectedTab }; QByteArray saveState(); bool restoreState(const QByteArray &state); @@ -67,7 +67,7 @@ signals: void pinnedTabAdded(); public slots: - void closeTab(int index=-1); + void closeTab(int index = -1); int addView(QUrl url = QUrl(), const QString &title = tr("New tab"), OpenUrlIn openIn = NewTab, bool selectLine = false); void reloadTab(int index) { weView(index)->reload(); } void reloadAllTabs(); @@ -91,7 +91,7 @@ private slots: void tabMoved(int before, int after); private: - void resizeEvent(QResizeEvent *e); + void resizeEvent(QResizeEvent* e); inline WebView* weView() { WebTab* webTab = qobject_cast(widget(currentIndex())); if (!webTab) return 0; return webTab->view(); } inline WebView* weView(int index) { WebTab* webTab = qobject_cast(widget(index)); if (!webTab) return 0; return webTab->view(); } diff --git a/src/webview/webhistorywrapper.cpp b/src/webview/webhistorywrapper.cpp index c23334fe0..aaa76f164 100644 --- a/src/webview/webhistorywrapper.cpp +++ b/src/webview/webhistorywrapper.cpp @@ -11,9 +11,10 @@ QList WebHistoryWrapper::forwardItems(int maxItems, QWebHistory QUrl lastUrl = history->currentItem().url(); int count = 0; - foreach (QWebHistoryItem item, history->forwardItems(maxItems + 5)) { - if (item.url() == lastUrl || count == maxItems) + foreach(QWebHistoryItem item, history->forwardItems(maxItems + 5)) { + if (item.url() == lastUrl || count == maxItems) { continue; + } lastUrl = item.url(); list.append(item); @@ -32,8 +33,9 @@ QList WebHistoryWrapper::backItems(int maxItems, QWebHistory* h QList bItems = history->backItems(maxItems + 5); for (int i = bItems.count() - 1; i >= 0; i--) { QWebHistoryItem item = bItems.at(i); - if (item.url() == lastUrl || count == maxItems) + if (item.url() == lastUrl || count == maxItems) { continue; + } lastUrl = item.url(); list.append(item); @@ -57,8 +59,9 @@ void WebHistoryWrapper::goBack(QWebHistory* history) { QList items = backItems(1, history); - if (items.isEmpty()) + if (items.isEmpty()) { return; + } history->goToItem(items.at(0)); } @@ -67,8 +70,9 @@ void WebHistoryWrapper::goForward(QWebHistory* history) { QList items = forwardItems(1, history); - if (items.isEmpty()) + if (items.isEmpty()) { return; + } history->goToItem(items.at(0)); } diff --git a/src/webview/webhistorywrapper.h b/src/webview/webhistorywrapper.h index 22ed33e35..2b8934010 100644 --- a/src/webview/webhistorywrapper.h +++ b/src/webview/webhistorywrapper.h @@ -9,7 +9,7 @@ class WebHistoryWrapper : public QObject { Q_OBJECT public: - explicit WebHistoryWrapper(QObject *parent = 0); + explicit WebHistoryWrapper(QObject* parent = 0); static QList forwardItems(int maxItems, QWebHistory* history); static QList backItems(int maxItems, QWebHistory* history); diff --git a/src/webview/webinspectordockwidget.cpp b/src/webview/webinspectordockwidget.cpp index 05acf5a91..e224bed8e 100644 --- a/src/webview/webinspectordockwidget.cpp +++ b/src/webview/webinspectordockwidget.cpp @@ -51,8 +51,9 @@ void WebInspectorDockWidget::show() setWidget(m_inspector); } - if (m_inspector->page() != p_QupZilla->weView()->page()) + if (m_inspector->page() != p_QupZilla->weView()->page()) { m_inspector->setPage(p_QupZilla->weView()->page()); + } p_QupZilla->weView()->webTab()->setInspectorVisible(true); @@ -61,14 +62,17 @@ void WebInspectorDockWidget::show() void WebInspectorDockWidget::tabChanged() { - if (p_QupZilla->weView()->webTab()->inspectorVisible()) + if (p_QupZilla->weView()->webTab()->inspectorVisible()) { show(); - else + } + else { close(); + } } WebInspectorDockWidget::~WebInspectorDockWidget() { - if (m_inspector) + if (m_inspector) { delete m_inspector; + } } diff --git a/src/webview/webpage.cpp b/src/webview/webpage.cpp index d64a80347..347ca6956 100644 --- a/src/webview/webpage.cpp +++ b/src/webview/webpage.cpp @@ -88,11 +88,12 @@ void WebPage::finished() void WebPage::handleUnsupportedContent(QNetworkReply* reply) { - if (!reply) + if (!reply) { return; + } QUrl url = reply->url(); - switch(reply->error()) { + switch (reply->error()) { case QNetworkReply::NoError: if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) { DownloadManager* dManager = mApp->downManager(); @@ -120,10 +121,12 @@ void WebPage::setSSLCertificate(const QSslCertificate &cert) QSslCertificate WebPage::sslCertificate() { if (mainFrame()->url().scheme() == "https" && - m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host()))) + m_SslCert.subjectInfo(QSslCertificate::CommonName).remove("*").contains(QRegExp(mainFrame()->url().host()))) { return m_SslCert; - else + } + else { return QSslCertificate(); + } } bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type) @@ -138,9 +141,10 @@ bool WebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &r if (type == QWebPage::NavigationTypeFormResubmitted) { bool result = javaScriptConfirm(frame, tr("To show this page, QupZilla must resend request which do it again \n" - "(like searching on making an shoping, which has been already done.)")); - if (!result) + "(like searching on making an shoping, which has been already done.)")); + if (!result) { return false; + } } // TabWidget::OpenUrlIn openIn= frame ? TabWidget::CurrentTab: TabWidget::NewTab; @@ -160,11 +164,11 @@ QString WebPage::userAgentForUrl(const QUrl &url) const void WebPage::populateNetworkRequest(QNetworkRequest &request) { - QVariant variant = qVariantFromValue((void *) this); + QVariant variant = qVariantFromValue((void*) this); request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant); request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), m_lastRequestType); - variant = qVariantFromValue((void *) m_view); + variant = qVariantFromValue((void*) m_view); request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102), variant); } @@ -188,17 +192,19 @@ void WebPage::addAdBlockRule(const QString &filter, const QUrl &url) entry.rule = filter; entry.url = url; - if (!m_adBlockedEntries.contains(entry)) + if (!m_adBlockedEntries.contains(entry)) { m_adBlockedEntries.append(entry); + } } void WebPage::cleanBlockedObjects() { QStringList findingStrings; - foreach (AdBlockedEntry entry, m_adBlockedEntries) { - if (entry.url.toString().endsWith(".js")) + foreach(AdBlockedEntry entry, m_adBlockedEntries) { + if (entry.url.toString().endsWith(".js")) { continue; + } findingStrings.append(entry.url.toString()); QUrl mainFrameUrl = mainFrame()->url(); @@ -206,23 +212,25 @@ void WebPage::cleanBlockedObjects() //May be relative url QString relativeUrl = qz_makeRelativeUrl(mainFrameUrl, entry.url).toString(); findingStrings.append(relativeUrl); - if (relativeUrl.startsWith("/")) + if (relativeUrl.startsWith("/")) { findingStrings.append(relativeUrl.right(relativeUrl.size() - 1)); + } } } QWebElement docElement = mainFrame()->documentElement(); QWebElementCollection elements; - foreach (QString s, findingStrings) - elements.append(docElement.findAll("*[src=\"" + s + "\"]")); - foreach (QWebElement element, elements) - element.setAttribute("style", "display:none;"); + foreach(QString s, findingStrings) + elements.append(docElement.findAll("*[src=\"" + s + "\"]")); + foreach(QWebElement element, elements) + element.setAttribute("style", "display:none;"); } bool WebPage::extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output) { - if (extension == ChooseMultipleFilesExtension) + if (extension == ChooseMultipleFilesExtension) { return QWebPage::extension(extension, option, output); + } const ErrorPageExtensionOption* exOption = static_cast(option); ErrorPageExtensionReturn* exReturn = static_cast(output); @@ -252,13 +260,15 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte QWebElementCollection elements; elements.append(docElement.findAll("iframe")); - foreach (QWebElement element, elements) { + foreach(QWebElement element, elements) { QString src = element.attribute("src"); - if (exOption->url.toString().contains(src)) + if (exOption->url.toString().contains(src)) { element.setAttribute("style", "display:none;"); + } } return false; - } else { //The whole page is blocked + } + else { //The whole page is blocked QString rule = exOption->errorString; rule.remove("AdBlockRule:"); @@ -295,8 +305,9 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte else if (exOption->domain == QWebPage::Http) { errorString = tr("Error code %1").arg(exOption->error); } - else if (exOption->domain == QWebPage::WebKit) - return false; // Downloads + else if (exOption->domain == QWebPage::WebKit) { + return false; // Downloads + } QString loadedUrl = exOption->url.toString(); exReturn->baseUrl = loadedUrl; @@ -306,8 +317,8 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte QString errString = file.readAll(); errString.replace("%TITLE%", tr("Failed loading page")); - errString.replace("%IMAGE%", qz_pixmapToByteArray(MainApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45,45))); - errString.replace("%FAVICON%", qz_pixmapToByteArray(MainApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(16,16))); + errString.replace("%IMAGE%", qz_pixmapToByteArray(MainApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(45, 45))); + errString.replace("%FAVICON%", qz_pixmapToByteArray(MainApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(16, 16))); errString.replace("%BOX-BORDER%", qz_pixmapToByteArray(QPixmap(":html/box-border.png"))); errString.replace("%HEADING%", errorString); @@ -343,13 +354,14 @@ bool WebPage::javaScriptPrompt(QWebFrame* originatingFrame, const QString &msg, QString width = QString::number(originatingFrame->contentsSize().width()); bodyElement.prependInside(" "); - } else { + "left: 0px;z-index: 998;overflow: hidden;width:" + width + "px; height:" + height + "px;'> "); + } + else { widget->setAutoFillBackground(true); } QEventLoop eLoop; - connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()) ); + connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit())); eLoop.exec(); QString x = ui->lineEdit->text(); @@ -383,13 +395,14 @@ bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg) QString width = QString::number(originatingFrame->contentsSize().width()); bodyElement.prependInside(" "); - } else { + "left: 0px;z-index: 998;overflow: hidden;width:" + width + "px; height:" + height + "px;'> "); + } + else { widget->setAutoFillBackground(true); } QEventLoop eLoop; - connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()) ); + connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit())); eLoop.exec(); bool result = ui->buttonBox->clickedButtonRole() == QDialogButtonBox::AcceptRole; @@ -403,8 +416,9 @@ bool WebPage::javaScriptConfirm(QWebFrame* originatingFrame, const QString &msg) void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg) { - if (m_blockAlerts) + if (m_blockAlerts) { return; + } WebView* _view = qobject_cast(originatingFrame->page()->view()); @@ -424,13 +438,14 @@ void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg) QString width = QString::number(originatingFrame->contentsSize().width()); bodyElement.prependInside(" "); - } else { + "left: 0px;z-index: 998;overflow: hidden;width:" + width + "px; height:" + height + "px;'> "); + } + else { widget->setAutoFillBackground(true); } QEventLoop eLoop; - connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit()) ); + connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), &eLoop, SLOT(quit())); eLoop.exec(); m_blockAlerts = ui->preventAlerts->isChecked(); @@ -441,17 +456,20 @@ void WebPage::javaScriptAlert(QWebFrame* originatingFrame, const QString &msg) _view->setFocus(); } -QString WebPage::chooseFile(QWebFrame *originatingFrame, const QString &oldFile) +QString WebPage::chooseFile(QWebFrame* originatingFrame, const QString &oldFile) { QString suggFileName; - if (oldFile.isEmpty()) + if (oldFile.isEmpty()) { suggFileName = m_lastUploadLocation; - else + } + else { suggFileName = oldFile; + } QString fileName = QFileDialog::getOpenFileName(originatingFrame->page()->view(), tr("Choose file..."), suggFileName); - if (!fileName.isEmpty()) + if (!fileName.isEmpty()) { m_lastUploadLocation = fileName; + } return fileName; } diff --git a/src/webview/webpage.h b/src/webview/webpage.h index 14990ae99..122117e11 100644 --- a/src/webview/webpage.h +++ b/src/webview/webpage.h @@ -42,8 +42,7 @@ public: QString rule; QUrl url; - bool operator==(const AdBlockedEntry &other) - { + bool operator==(const AdBlockedEntry &other) const { return (this->rule == other.rule && this->url == other.url); } }; @@ -87,7 +86,7 @@ private: virtual bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0); bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type); - QString chooseFile(QWebFrame *originatingFrame, const QString &oldFile); + QString chooseFile(QWebFrame* originatingFrame, const QString &oldFile); static QString m_lastUploadLocation; QupZilla* p_QupZilla; diff --git a/src/webview/webtab.cpp b/src/webview/webtab.cpp index 3d54b9d06..9020e0cb5 100644 --- a/src/webview/webtab.cpp +++ b/src/webview/webtab.cpp @@ -31,7 +31,7 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar) , m_inspectorVisible(false) { m_layout = new QVBoxLayout(this); - m_layout->setContentsMargins(0,0,0,0); + m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setSpacing(0); m_view = new WebView(p_QupZilla, this); @@ -52,8 +52,9 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar) void WebTab::showNotification(QWidget* notif) { - if (m_layout->count() > 1) + if (m_layout->count() > 1) { delete m_layout->itemAt(0)->widget(); + } m_layout->insertWidget(0, notif); notif->show(); @@ -67,14 +68,16 @@ int WebTab::tabIndex() void WebTab::pinTab(int index) { TabWidget* tabWidget = p_QupZilla->tabWidget(); - if (!tabWidget) + if (!tabWidget) { return; + } if (m_pinned) { //Unpin tab m_pinned = false; tabWidget->setTabText(index, m_view->title()); tabWidget->getTabBar()->updateCloseButton(index); - } else { // Pin tab + } + else { // Pin tab m_pinned = true; tabWidget->setCurrentIndex(0); // <<-- those 2 lines fixes tabWidget->getTabBar()->moveTab(index, 0); // | weird behavior with bad diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 916593d9e..32b5f424e 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -99,8 +99,9 @@ void WebView::slotIconChanged() { m_siteIcon = icon(); - if (url().toString().contains("file://") || title().contains(tr("Failed loading page"))) + if (url().toString().contains("file://") || title().contains(tr("Failed loading page"))) { return; + } mApp->iconProvider()->saveIcon(this); } @@ -141,22 +142,26 @@ WebTab* WebView::webTab() const bool WebView::isCurrent() { - if (!tabWidget()) + if (!tabWidget()) { return false; + } WebTab* webTab = qobject_cast(tabWidget()->widget(tabWidget()->currentIndex())); - if (!webTab) + if (!webTab) { return false; + } return (webTab->view() == this); } void WebView::urlChanged(const QUrl &url) { - if (isCurrent()) + if (isCurrent()) { p_QupZilla->navigationBar()->refreshHistory(); + } - if (m_lastUrl != url) + if (m_lastUrl != url) { emit changed(); + } emit showUrl(url); } @@ -170,8 +175,9 @@ void WebView::setProgress(int prog) { m_progress = prog; - if (prog > 60) + if (prog > 60) { checkRss(); + } if (isCurrent()) { p_QupZilla->ipLabel()->hide(); @@ -188,10 +194,11 @@ void WebView::loadStarted() m_rssChecked = false; emit rssChanged(false); - animationLoading(tabIndex(),true); + animationLoading(tabIndex(), true); - if (title().isNull()) - tabWidget()->setTabText(tabIndex(),tr("Loading...")); + if (title().isNull()) { + tabWidget()->setTabText(tabIndex(), tr("Loading...")); + } m_currentIp.clear(); @@ -204,8 +211,9 @@ void WebView::loadStarted() QLabel* WebView::animationLoading(int index, bool addMovie) { - if (-1 == index) + if (-1 == index) { return 0; + } QLabel* loadingAnimation = qobject_cast(tabWidget()->getTabBar()->tabButton(index, QTabBar::LeftSide)); if (!loadingAnimation) { @@ -218,8 +226,9 @@ QLabel* WebView::animationLoading(int index, bool addMovie) loadingAnimation->setMovie(movie); movie->start(); } - else if (loadingAnimation->movie()) + else if (loadingAnimation->movie()) { loadingAnimation->movie()->stop(); + } tabWidget()->getTabBar()->setTabButton(index, QTabBar::LeftSide, 0); tabWidget()->getTabBar()->setTabButton(index, QTabBar::LeftSide, loadingAnimation); @@ -238,28 +247,33 @@ void WebView::stopAnimation() void WebView::setIp(const QHostInfo &info) { - if (info.addresses().isEmpty()) + if (info.addresses().isEmpty()) { return; - m_currentIp = info.hostName() + " ("+info.addresses().at(0).toString()+")"; + } + m_currentIp = info.hostName() + " (" + info.addresses().at(0).toString() + ")"; - if (isCurrent()) + if (isCurrent()) { emit ipChanged(m_currentIp); + } } void WebView::loadFinished(bool state) { Q_UNUSED(state); - if (mApp->isClosing() || p_QupZilla->isClosing()) + if (mApp->isClosing() || p_QupZilla->isClosing()) { return; + } - if (animationLoading(tabIndex(), false)->movie()) + if (animationLoading(tabIndex(), false)->movie()) { animationLoading(tabIndex(), false)->movie()->stop(); + } m_isLoading = false; - if (m_lastUrl != url()) + if (m_lastUrl != url()) { mApp->history()->addHistoryEntry(this); + } emit showUrl(url()); @@ -267,8 +281,9 @@ void WebView::loadFinished(bool state) m_lastUrl = url(); //Icon is sometimes not available at the moment of finished loading - if (icon().isNull()) + if (icon().isNull()) { QTimer::singleShot(1000, this, SLOT(iconChanged())); + } titleChanged(); mApp->autoFill()->completePage(this); @@ -287,39 +302,46 @@ void WebView::titleChanged() { QString title_ = title(); QString title2 = title_; - tabWidget()->setTabToolTip(tabIndex(),title2); + tabWidget()->setTabToolTip(tabIndex(), title2); title2 += " - QupZilla"; - if (isCurrent()) + if (isCurrent()) { p_QupZilla->setWindowTitle(title2); + } tabWidget()->setTabText(tabIndex(), title_); } void WebView::iconChanged() { - if (mApp->isClosing() || p_QupZilla->isClosing()) + if (mApp->isClosing() || p_QupZilla->isClosing()) { return; + } // if (isCurrent()) - emit siteIconChanged(); + emit siteIconChanged(); - if (m_isLoading) + if (m_isLoading) { return; + } QIcon icon_ = siteIcon(); - if (!icon_.isNull()) - animationLoading(tabIndex(), false)->setPixmap(icon_.pixmap(16,16)); - else - animationLoading(tabIndex(), false)->setPixmap(IconProvider::fromTheme("text-plain").pixmap(16,16)); + if (!icon_.isNull()) { + animationLoading(tabIndex(), false)->setPixmap(icon_.pixmap(16, 16)); + } + else { + animationLoading(tabIndex(), false)->setPixmap(IconProvider::fromTheme("text-plain").pixmap(16, 16)); + } } QIcon WebView::siteIcon() { - if (!icon().isNull()) + if (!icon().isNull()) { return icon(); - if (!m_siteIcon.isNull()) + } + if (!m_siteIcon.isNull()) { return m_siteIcon; + } return _iconForUrl(url()); } @@ -328,10 +350,12 @@ void WebView::linkHovered(const QString &link, const QString &title, const QStri Q_UNUSED(title); Q_UNUSED(content); if (isCurrent()) { - if (link!="") + if (link != "") { p_QupZilla->statusBarMessage()->showMessage(link); - else + } + else { p_QupZilla->statusBarMessage()->clearMessage(); + } } m_hoveredLink = link; } @@ -340,8 +364,9 @@ TabWidget* WebView::tabWidget() const { QObject* widget = this->parent(); while (widget) { - if (TabWidget* tw = qobject_cast(widget)) + if (TabWidget* tw = qobject_cast(widget)) { return tw; + } widget = widget->parent(); } return 0; @@ -350,11 +375,12 @@ TabWidget* WebView::tabWidget() const int WebView::tabIndex() const { TabWidget* tabWid = tabWidget(); - if (!tabWid) + if (!tabWid) { return -1; + } int i = 0; - while(qobject_cast(tabWid->widget(i))->view()!=this) { + while (qobject_cast(tabWid->widget(i))->view() != this) { i++; } return i; @@ -366,12 +392,14 @@ QUrl WebView::guessUrlFromString(const QString &string) // Check the most common case of a valid url with scheme and host first QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); - if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) + if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) { return url; + } // Absolute files that exists - if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString)) + if (QDir::isAbsolutePath(trimmedString) && QFile::exists(trimmedString)) { return QUrl::fromLocalFile(trimmedString); + } // If the string is missing the scheme or the scheme is not valid prepend a scheme QString scheme = url.scheme(); @@ -386,16 +414,18 @@ QUrl WebView::guessUrlFromString(const QString &string) url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode); } - if (url.isValid()) + if (url.isValid()) { return url; + } return QUrl(); } void WebView::checkRss() { - if (m_rssChecked) + if (m_rssChecked) { return; + } m_rssChecked = true; QWebFrame* frame = page()->mainFrame(); @@ -415,16 +445,19 @@ void WebView::mousePressEvent(QMouseEvent* event) forward(); break; case Qt::MiddleButton: - if (isUrlValid(QUrl(m_hoveredLink))) - tabWidget()->addView(QUrl::fromEncoded(m_hoveredLink.toAscii()),tr("New tab"), TabWidget::NewNotSelectedTab); + if (isUrlValid(QUrl(m_hoveredLink))) { + tabWidget()->addView(QUrl::fromEncoded(m_hoveredLink.toAscii()), tr("New tab"), TabWidget::NewNotSelectedTab); + event->accept(); + } #ifdef Q_WS_WIN - else + else { QWebView::mouseDoubleClickEvent(event); + } #endif break; case Qt::LeftButton: if (event->modifiers() == Qt::ControlModifier && isUrlValid(QUrl(m_hoveredLink))) { - tabWidget()->addView(QUrl::fromEncoded(m_hoveredLink.toAscii()),tr("New tab"), TabWidget::NewNotSelectedTab); + tabWidget()->addView(QUrl::fromEncoded(m_hoveredLink.toAscii()), tr("New tab"), TabWidget::NewNotSelectedTab); return; } default: @@ -433,7 +466,7 @@ void WebView::mousePressEvent(QMouseEvent* event) } } -void WebView::resizeEvent(QResizeEvent *event) +void WebView::resizeEvent(QResizeEvent* event) { QWebView::resizeEvent(event); emit viewportResized(m_page->viewportSize()); @@ -442,17 +475,19 @@ void WebView::resizeEvent(QResizeEvent *event) void WebView::mouseReleaseEvent(QMouseEvent* event) { //Workaround for crash in mouseReleaseEvent when closing tab from javascript :/ - if (!m_wantsClose) + if (!m_wantsClose) { QWebView::mouseReleaseEvent(event); + } } -void WebView::mouseMoveEvent(QMouseEvent *event) +void WebView::mouseMoveEvent(QMouseEvent* event) { if (m_mouseTrack) { if (m_navigationVisible) { m_navigationVisible = false; p_QupZilla->showNavigationWithFullscreen(); - } else if (event->y() < 5) { + } + else if (event->y() < 5) { m_navigationVisible = true; p_QupZilla->showNavigationWithFullscreen(); } @@ -466,9 +501,10 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos()); - if (!r.linkUrl().isEmpty() && r.linkUrl().scheme()!="javascript") { - if (page()->selectedText() == r.linkText()) + if (!r.linkUrl().isEmpty() && r.linkUrl().scheme() != "javascript") { + if (page()->selectedText() == r.linkText()) { findText(""); + } menu->addAction(QIcon(":/icons/menu/popup.png"), tr("Open link in new &tab"), this, SLOT(openUrlInNewTab()))->setData(r.linkUrl()); menu->addAction(tr("Open link in new &window"), this, SLOT(openUrlInNewWindow()))->setData(r.linkUrl()); menu->addSeparator(); @@ -477,13 +513,15 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) menu->addAction(tr("Send link..."), this, SLOT(sendLinkByMail()))->setData(r.linkUrl()); menu->addAction(QIcon::fromTheme("edit-copy"), tr("&Copy link address"), this, SLOT(copyLinkToClipboard()))->setData(r.linkUrl()); menu->addSeparator(); - if (!selectedText().isEmpty()) + if (!selectedText().isEmpty()) { menu->addAction(pageAction(QWebPage::Copy)); + } } if (!r.imageUrl().isEmpty()) { - if (!menu->isEmpty()) + if (!menu->isEmpty()) { menu->addSeparator(); + } menu->addAction(tr("Show i&mage"), this, SLOT(showImage()))->setData(r.imageUrl()); menu->addAction(tr("Copy im&age"), this, SLOT(copyImageToClipboard()))->setData(r.imageUrl()); menu->addAction(QIcon::fromTheme("edit-copy"), tr("Copy image ad&dress"), this, SLOT(copyLinkToClipboard()))->setData(r.imageUrl()); @@ -492,17 +530,18 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) menu->addAction(tr("Send image..."), this, SLOT(sendLinkByMail()))->setData(r.linkUrl()); menu->addSeparator(); //menu->addAction(tr("Block image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString()); - if (!selectedText().isEmpty()) + if (!selectedText().isEmpty()) { menu->addAction(pageAction(QWebPage::Copy)); + } } QWebElement element = r.element(); - if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea")) { - if (menu->isEmpty()) { - delete menu; - menu = page()->createStandardContextMenu(); - } - } + if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea")) { + if (menu->isEmpty()) { + delete menu; + menu = page()->createStandardContextMenu(); + } + } if (menu->isEmpty()) { QAction* action = menu->addAction(tr("&Back"), this, SLOT(back())); @@ -524,12 +563,13 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) menu->addAction(tr("Send page..."), this, SLOT(sendLinkByMail()))->setData(url()); menu->addSeparator(); menu->addAction(QIcon::fromTheme("edit-select-all"), tr("Select &all"), this, SLOT(selectAll())); - if (!selectedText().isEmpty()) + if (!selectedText().isEmpty()) { menu->addAction(pageAction(QWebPage::Copy)); + } menu->addSeparator(); - menu->addAction(QIcon::fromTheme("text-html"),tr("Show so&urce code"), this, SLOT(showSource())); - menu->addAction(QIcon::fromTheme("dialog-information"),tr("Show info ab&out site"), this, SLOT(showSiteInfo()))->setData(url()); + menu->addAction(QIcon::fromTheme("text-html"), tr("Show so&urce code"), this, SLOT(showSource())); + menu->addAction(QIcon::fromTheme("dialog-information"), tr("Show info ab&out site"), this, SLOT(showSiteInfo()))->setData(url()); menu->addAction(tr("Show Web &Inspector"), this, SLOT(showInspector())); } @@ -552,7 +592,7 @@ void WebView::contextMenuEvent(QContextMenuEvent* event) if (!menu->isEmpty()) { //Prevent choosing first option with double rightclick QPoint pos = QCursor::pos(); - QPoint p(pos.x(), pos.y()+1); + QPoint p(pos.x(), pos.y() + 1); menu->exec(p); delete menu; return; @@ -568,8 +608,9 @@ void WebView::stop() page()->triggerAction(QWebPage::Stop); loadFinished(true); - if (m_locationBar->text().isEmpty()) + if (m_locationBar->text().isEmpty()) { m_locationBar->setText(url().toEncoded()); + } } } @@ -595,7 +636,7 @@ void WebView::openUrlInNewWindow() void WebView::sendLinkByMail() { if (QAction* action = qobject_cast(sender())) { - QDesktopServices::openUrl(QUrl("mailto:?body="+action->data().toString())); + QDesktopServices::openUrl(QUrl("mailto:?body=" + action->data().toString())); } } @@ -668,10 +709,12 @@ void WebView::downloadRequested(const QNetworkRequest &request) void WebView::bookmarkLink() { if (QAction* action = qobject_cast(sender())) { - if (action->data().isNull()) + if (action->data().isNull()) { p_QupZilla->bookmarkPage(); - else + } + else { p_QupZilla->addBookmark(action->data().toUrl(), action->data().toString(), siteIcon()); + } } } @@ -694,8 +737,9 @@ void WebView::zoomIn() { int i = m_zoomLevels.indexOf(m_currentZoom); - if (i < m_zoomLevels.count() - 1) + if (i < m_zoomLevels.count() - 1) { m_currentZoom = m_zoomLevels[i + 1]; + } applyZoom(); } @@ -703,8 +747,9 @@ void WebView::zoomOut() { int i = m_zoomLevels.indexOf(m_currentZoom); - if (i > 0) + if (i > 0) { m_currentZoom = m_zoomLevels[i - 1]; + } applyZoom(); } @@ -719,27 +764,32 @@ void WebView::wheelEvent(QWheelEvent* event) if (event->modifiers() & Qt::ControlModifier) { int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; - if (numSteps == 1) + if (numSteps == 1) { zoomIn(); - else + } + else { zoomOut(); + } event->accept(); return; } - if (m_mouseWheelEnabled) + if (m_mouseWheelEnabled) { QWebView::wheelEvent(event); + } } void WebView::getFocus(const QUrl &urla) { - if (urla == url()) + if (urla == url()) { tabWidget()->setCurrentWidget(this); + } } void WebView::closeTab() { - if (m_wantsClose) + if (m_wantsClose) { emit wantsCloseTab(tabIndex()); + } else { m_wantsClose = true; QTimer::singleShot(20, this, SLOT(closeTab())); @@ -767,7 +817,7 @@ void WebView::load(const QUrl &url) #ifdef Q_WS_WIN if (QFile::exists(url.path().mid(1))) // From QUrl(file:///C:/Bla/ble/foo.html it returns - // /C:/Bla/ble/foo.html ... so we cut first char + // /C:/Bla/ble/foo.html ... so we cut first char #else if (QFile::exists(url.path())) #endif @@ -783,18 +833,24 @@ void WebView::load(const QUrl &url) QUrl WebView::url() const { QUrl ur = QWebView::url(); - if (ur.isEmpty() && !m_aboutToLoadUrl.isEmpty()) + if (ur.isEmpty() && !m_aboutToLoadUrl.isEmpty()) { return m_aboutToLoadUrl; + } return ur; } QString WebView::title() const { QString title = QWebView::title(); - if (title.isEmpty()) title = url().host(); - if (title.isEmpty()) title = url().path(); - if (title.isEmpty()) + if (title.isEmpty()) { + title = url().host(); + } + if (title.isEmpty()) { + title = url().path(); + } + if (title.isEmpty()) { return tr("No Named Page"); + } return title; } @@ -810,11 +866,13 @@ void WebView::reload() bool WebView::isUrlValid(const QUrl &url) { - if (url.scheme() == "qupzilla") + if (url.scheme() == "qupzilla") { return true; + } - if (url.isValid() && !url.host().isEmpty() && !url.scheme().isEmpty()) + if (url.isValid() && !url.host().isEmpty() && !url.scheme().isEmpty()) { return true; + } return false; } @@ -826,22 +884,25 @@ bool WebView::isUrlValid(const QUrl &url) bool WebView::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::MouseButtonPress || - event->type() == QEvent::MouseButtonRelease || - event->type() == QEvent::MouseButtonDblClick || - event->type() == QEvent::MouseMove) { + event->type() == QEvent::MouseButtonRelease || + event->type() == QEvent::MouseButtonDblClick || + event->type() == QEvent::MouseMove) { QMouseEvent* ev = static_cast(event); if (ev->type() == QEvent::MouseMove - && !(ev->buttons() & Qt::LeftButton)) + && !(ev->buttons() & Qt::LeftButton)) { return false; + } QTouchEvent::TouchPoint touchPoint; touchPoint.setState(Qt::TouchPointMoved); if ((ev->type() == QEvent::MouseButtonPress - || ev->type() == QEvent::MouseButtonDblClick)) + || ev->type() == QEvent::MouseButtonDblClick)) { touchPoint.setState(Qt::TouchPointPressed); - else if (ev->type() == QEvent::MouseButtonRelease) + } + else if (ev->type() == QEvent::MouseButtonRelease) { touchPoint.setState(Qt::TouchPointReleased); + } touchPoint.setId(0); touchPoint.setScreenPos(ev->globalPos()); @@ -849,20 +910,25 @@ bool WebView::eventFilter(QObject* obj, QEvent* event) touchPoint.setPressure(1); // If the point already exists, update it. Otherwise create it. - if (m_touchPoints.size() > 0 && !m_touchPoints[0].id()) + if (m_touchPoints.size() > 0 && !m_touchPoints[0].id()) { m_touchPoints[0] = touchPoint; - else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id()) + } + else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id()) { m_touchPoints[1] = touchPoint; - else + } + else { m_touchPoints.append(touchPoint); + } if (!m_touchPoints.isEmpty()) { QEvent::Type type = QEvent::TouchUpdate; if (m_touchPoints.size() == 1) { - if (m_touchPoints[0].state() == Qt::TouchPointReleased) + if (m_touchPoints[0].state() == Qt::TouchPointReleased) { type = QEvent::TouchEnd; - else if (m_touchPoints[0].state() == Qt::TouchPointPressed) + } + else if (m_touchPoints[0].state() == Qt::TouchPointPressed) { type = QEvent::TouchBegin; + } } QTouchEvent touchEv(type); @@ -870,10 +936,12 @@ bool WebView::eventFilter(QObject* obj, QEvent* event) QCoreApplication::sendEvent(page(), &touchEv); // After sending the event, remove all touchpoints that were released - if (m_touchPoints[0].state() == Qt::TouchPointReleased) + if (m_touchPoints[0].state() == Qt::TouchPointReleased) { m_touchPoints.removeAt(0); - if (m_touchPoints.size() > 1 && m_touchPoints[1].state() == Qt::TouchPointReleased) + } + if (m_touchPoints.size() > 1 && m_touchPoints[1].state() == Qt::TouchPointReleased) { m_touchPoints.removeAt(1); + } } return false; diff --git a/translations/cs_CZ.ts b/translations/cs_CZ.ts index f9313e917..5fab35ff6 100644 --- a/translations/cs_CZ.ts +++ b/translations/cs_CZ.ts @@ -3452,7 +3452,7 @@ Po přidání či odstranění cest k certifikátům je nutné k projevení změ <b>NOTE:</b> Setting this option is big security risk! - <b>Poznámka.</b> Zaškrtnutím této možnosti se vystavujete velikému bezpečnostnímu riziku! + <b>Poznámka:</b> Zaškrtnutím této možnosti se vystavujete velikému bezpečnostnímu riziku! diff --git a/windows/installer.nsi b/windows/installer.nsi index 4c9b90dd8..9b7290e98 100644 --- a/windows/installer.nsi +++ b/windows/installer.nsi @@ -154,6 +154,12 @@ SectionGroup $(TITLE_SecTranslations) SecTranslations File "locale\qt_nl.qm" SectionEnd + Section "Italian" + SetOutPath "$INSTDIR\locale" + File "locale\it_IT.qm" + File "locale\qt_it.qm" + SectionEnd + Section "Chinese" SetOutPath "$INSTDIR\locale" File "locale\zh_CN.qm"