diff --git a/src/app/autosaver.cpp b/src/app/autosaver.cpp index e8b42013f..3913d20aa 100644 --- a/src/app/autosaver.cpp +++ b/src/app/autosaver.cpp @@ -26,7 +26,7 @@ AutoSaver::AutoSaver(QObject* parent) : void AutoSaver::timerEvent(QTimerEvent* event) { - if (event->timerId() == m_timer.timerId() && mApp->isChanged()) + if (event->timerId() == m_timer.timerId() && mApp->isStateChanged()) emit saveApp(); else QObject::timerEvent(event); diff --git a/src/app/mainapplication.cpp b/src/app/mainapplication.cpp index 918e89366..43a99fc51 100644 --- a/src/app/mainapplication.cpp +++ b/src/app/mainapplication.cpp @@ -55,7 +55,7 @@ MainApplication::MainApplication(const QList &cm ,m_desktopNotifications(0) ,m_iconProvider(new IconProvider) ,m_isClosing(false) - ,m_isChanged(false) + ,m_isStateChanged(false) ,m_isExited(false) ,m_isRestoring(false) { @@ -239,10 +239,16 @@ QupZilla* MainApplication::getWindow() return 0; } -bool MainApplication::isChanged() +void MainApplication::setStateChanged() { - if (m_isChanged) { - m_isChanged = false; + m_isStateChanged = true; + sendMessages(StateChanged, true); +} + +bool MainApplication::isStateChanged() +{ + if (m_isStateChanged) { + m_isStateChanged = false; return true; } return false; diff --git a/src/app/mainapplication.h b/src/app/mainapplication.h index ad4d3d221..3d9525cc9 100644 --- a/src/app/mainapplication.h +++ b/src/app/mainapplication.h @@ -55,7 +55,7 @@ public: QString DATADIR; explicit MainApplication(const QList &cmdActions, int &argc, char **argv); - enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing , ReloadSettings }; + enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing, ReloadSettings, StateChanged }; void loadSettings(); void reloadSettings() { loadSettings(); emit message(ReloadSettings, true); } @@ -63,7 +63,7 @@ public: void makeNewWindow(bool tryRestore, const QUrl &startUrl=QUrl()); void addNewTab(const QUrl &url = QUrl()); void aboutToCloseWindow(QupZilla* window); - bool isChanged(); + bool isStateChanged(); inline static MainApplication* getInstance() { return static_cast(QCoreApplication::instance()); } inline QString getActiveProfil() { return m_activeProfil; } @@ -99,7 +99,7 @@ public slots: void quitApplication(); void sendMessages(MainApplication::MessageType mes, bool state); void receiveAppMessage(QString message); - inline void setChanged() { m_isChanged = true; } + void setStateChanged(); signals: void message(MainApplication::MessageType mes, bool state); @@ -136,7 +136,7 @@ private: QString m_activeLanguage; bool m_isClosing; - bool m_isChanged; + bool m_isStateChanged; bool m_isExited; bool m_isRestoring; }; diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index 62496bae9..9acdac009 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -66,6 +66,7 @@ const QString QupZilla::WEBKITVERSION = qWebKitVersion(); QupZilla::QupZilla(bool tryRestore, QUrl startUrl) : QMainWindow(0) ,m_tryRestore(tryRestore) + ,m_historyMenuChanged(true) ,m_startingUrl(startUrl) ,m_actionPrivateBrowsing(0) ,m_webInspectorDock(0) @@ -359,6 +360,9 @@ void QupZilla::setupMenu() menuBar()->setContextMenuPolicy(Qt::CustomContextMenu); + m_menuClosedTabs = new QMenu(tr("Closed Tabs")); + connect(m_menuClosedTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu())); + aboutToShowToolsMenu(); aboutToShowHelpMenu(); @@ -501,8 +505,12 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state) LocationBarSettings::instance()->loadSettings(); break; + case MainApplication::StateChanged: + m_historyMenuChanged = true; + break; + default: - qWarning("Unresolved message sent!"); + qWarning("Unresolved message sent! This could never happen!"); break; } } @@ -646,6 +654,11 @@ void QupZilla::aboutToShowHistoryMenu() { if (!weView()) return; + + if (!m_historyMenuChanged) + return; + m_historyMenuChanged = false; + m_menuHistory->clear(); m_menuHistory->addAction( #ifdef Q_WS_X11 @@ -689,7 +702,12 @@ void QupZilla::aboutToShowHistoryMenu() m_menuHistory->addAction(_iconForUrl(url), title, this, SLOT(loadActionUrl()))->setData(url); } m_menuHistory->addSeparator(); - QMenu* menuClosedTabs = new QMenu(tr("Closed Tabs")); + m_menuHistory->addMenu(m_menuClosedTabs); +} + +void QupZilla::aboutToShowClosedTabsMenu() +{ + m_menuClosedTabs->clear(); int i = 0; foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) { QString title = tab.title; @@ -697,16 +715,14 @@ void QupZilla::aboutToShowHistoryMenu() title.truncate(40); title+=".."; } - menuClosedTabs->addAction(_iconForUrl(tab.url), title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i); + m_menuClosedTabs->addAction(_iconForUrl(tab.url), title, m_tabWidget, SLOT(restoreClosedTab()))->setData(i); i++; } - menuClosedTabs->addSeparator(); + m_menuClosedTabs->addSeparator(); if (i == 0) - menuClosedTabs->addAction(tr("Empty"))->setEnabled(false); + m_menuClosedTabs->addAction(tr("Empty"))->setEnabled(false); else - menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs())); - - m_menuHistory->addMenu(menuClosedTabs); + m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs())); } void QupZilla::aboutToShowHelpMenu() diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index 74481438a..7c9c544eb 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -148,6 +148,7 @@ private slots: void aboutToShowHistoryBackMenu(); void aboutToShowHistoryNextMenu(); void aboutToShowHistoryMenu(); + void aboutToShowClosedTabsMenu(); void aboutToShowBookmarksMenu(); void aboutToShowToolsMenu(); void aboutToShowHelpMenu(); @@ -197,6 +198,7 @@ private: void setupMenu(); bool m_tryRestore; + bool m_historyMenuChanged; QUrl m_startingUrl; QUrl m_newtab; QUrl m_homepage; @@ -210,6 +212,7 @@ private: QMenu* m_menuView; QMenu* m_menuBookmarks; QMenu* m_menuHistory; + QMenu* m_menuClosedTabs; QMenu* m_menuBack; QMenu* m_menuForward; QMenu* m_menuEncoding; diff --git a/src/downloads/downloaditem.cpp b/src/downloads/downloaditem.cpp index 7d8580eb9..5fdad7b90 100644 --- a/src/downloads/downloaditem.cpp +++ b/src/downloads/downloaditem.cpp @@ -46,6 +46,7 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString QFile::remove(fullPath); m_outputFile.setFileName(fullPath); + qDebug() << m_fileName << m_outputFile.fileName(); ui->setupUi(this); setMaximumWidth(525); diff --git a/src/downloads/downloadmanager.cpp b/src/downloads/downloadmanager.cpp index 487e49dd1..0f319cf0f 100644 --- a/src/downloads/downloadmanager.cpp +++ b/src/downloads/downloadmanager.cpp @@ -214,12 +214,12 @@ void DownloadManager::optionsDialogAccepted(int finish) } } else - fileNameChoosed(m_downloadPath + m_h_fileName); + fileNameChoosed(m_downloadPath + m_h_fileName, true); } else - fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName); + fileNameChoosed(QDir::tempPath() + "/" + m_h_fileName, true); } -void DownloadManager::fileNameChoosed(const QString &name) +void DownloadManager::fileNameChoosed(const QString &name, bool fileNameAutoGenerated) { m_huserFileName = name; if (m_huserFileName.isEmpty()) { @@ -236,6 +236,23 @@ void DownloadManager::fileNameChoosed(const QString &name) m_hfileName = m_huserFileName.right(size-pos-1); } + if (fileNameAutoGenerated && QFile::exists(m_huserFileName)) { + QString _tmpFileName = m_hfileName; + int i = 1; + while (QFile::exists(m_hpath + "/" + _tmpFileName)) { + _tmpFileName = m_hfileName; + int index = _tmpFileName.lastIndexOf("."); + + if (index == -1) { + _tmpFileName.append("("+QString::number(i)+")"); + } else { + _tmpFileName = _tmpFileName.mid(0, index) + "("+QString::number(i)+")" + _tmpFileName.mid(index); + } + i++; + } + m_hfileName = _tmpFileName; + } + if (!m_hpath.contains(QDir::tempPath())) m_lastDownloadPath = m_hpath; diff --git a/src/downloads/downloadmanager.h b/src/downloads/downloadmanager.h index 12c54983a..491d8b574 100644 --- a/src/downloads/downloadmanager.h +++ b/src/downloads/downloadmanager.h @@ -73,7 +73,7 @@ private slots: void optionsDialogAccepted(int finish); - void fileNameChoosed(const QString &name = ""); + void fileNameChoosed(const QString &name, bool fileNameAutoGenerated = false); signals: void resized(QSize); diff --git a/src/webview/tabwidget.cpp b/src/webview/tabwidget.cpp index 6b1602d48..1e16b6799 100644 --- a/src/webview/tabwidget.cpp +++ b/src/webview/tabwidget.cpp @@ -239,7 +239,7 @@ int TabWidget::addView(QUrl url, const QString &title, OpenUrlIn openIn, bool se // connect(weView(index), SIGNAL(siteIconChanged()), p_QupZilla->locationBar(), SLOT(siteIconChanged())); // connect(weView(index), SIGNAL(showUrl(QUrl)), p_QupZilla->locationBar(), SLOT(showUrl(QUrl))); connect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); - connect(webView, SIGNAL(changed()), mApp, SLOT(setChanged())); + connect(webView, SIGNAL(changed()), mApp, SLOT(setStateChanged())); connect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString))); if (url.isValid())