1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

Download Manager: opening file with the name which already exists now

rename it with number suffix.
History Menu: is now generated only when webview's state is changed
This commit is contained in:
nowrep 2011-07-28 12:12:00 +02:00
parent 23bebb3b9d
commit cf3a621346
9 changed files with 65 additions and 22 deletions

View File

@ -26,7 +26,7 @@ AutoSaver::AutoSaver(QObject* parent) :
void AutoSaver::timerEvent(QTimerEvent* event) void AutoSaver::timerEvent(QTimerEvent* event)
{ {
if (event->timerId() == m_timer.timerId() && mApp->isChanged()) if (event->timerId() == m_timer.timerId() && mApp->isStateChanged())
emit saveApp(); emit saveApp();
else else
QObject::timerEvent(event); QObject::timerEvent(event);

View File

@ -55,7 +55,7 @@ MainApplication::MainApplication(const QList<CommandLineOptions::ActionPair> &cm
,m_desktopNotifications(0) ,m_desktopNotifications(0)
,m_iconProvider(new IconProvider) ,m_iconProvider(new IconProvider)
,m_isClosing(false) ,m_isClosing(false)
,m_isChanged(false) ,m_isStateChanged(false)
,m_isExited(false) ,m_isExited(false)
,m_isRestoring(false) ,m_isRestoring(false)
{ {
@ -239,10 +239,16 @@ QupZilla* MainApplication::getWindow()
return 0; return 0;
} }
bool MainApplication::isChanged() void MainApplication::setStateChanged()
{ {
if (m_isChanged) { m_isStateChanged = true;
m_isChanged = false; sendMessages(StateChanged, true);
}
bool MainApplication::isStateChanged()
{
if (m_isStateChanged) {
m_isStateChanged = false;
return true; return true;
} }
return false; return false;

View File

@ -55,7 +55,7 @@ public:
QString DATADIR; QString DATADIR;
explicit MainApplication(const QList<CommandLineOptions::ActionPair> &cmdActions, int &argc, char **argv); explicit MainApplication(const QList<CommandLineOptions::ActionPair> &cmdActions, int &argc, char **argv);
enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing , ReloadSettings }; enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing, ReloadSettings, StateChanged };
void loadSettings(); void loadSettings();
void reloadSettings() { loadSettings(); emit message(ReloadSettings, true); } void reloadSettings() { loadSettings(); emit message(ReloadSettings, true); }
@ -63,7 +63,7 @@ public:
void makeNewWindow(bool tryRestore, const QUrl &startUrl=QUrl()); void makeNewWindow(bool tryRestore, const QUrl &startUrl=QUrl());
void addNewTab(const QUrl &url = QUrl()); void addNewTab(const QUrl &url = QUrl());
void aboutToCloseWindow(QupZilla* window); void aboutToCloseWindow(QupZilla* window);
bool isChanged(); bool isStateChanged();
inline static MainApplication* getInstance() { return static_cast<MainApplication*>(QCoreApplication::instance()); } inline static MainApplication* getInstance() { return static_cast<MainApplication*>(QCoreApplication::instance()); }
inline QString getActiveProfil() { return m_activeProfil; } inline QString getActiveProfil() { return m_activeProfil; }
@ -99,7 +99,7 @@ public slots:
void quitApplication(); void quitApplication();
void sendMessages(MainApplication::MessageType mes, bool state); void sendMessages(MainApplication::MessageType mes, bool state);
void receiveAppMessage(QString message); void receiveAppMessage(QString message);
inline void setChanged() { m_isChanged = true; } void setStateChanged();
signals: signals:
void message(MainApplication::MessageType mes, bool state); void message(MainApplication::MessageType mes, bool state);
@ -136,7 +136,7 @@ private:
QString m_activeLanguage; QString m_activeLanguage;
bool m_isClosing; bool m_isClosing;
bool m_isChanged; bool m_isStateChanged;
bool m_isExited; bool m_isExited;
bool m_isRestoring; bool m_isRestoring;
}; };

View File

@ -66,6 +66,7 @@ const QString QupZilla::WEBKITVERSION = qWebKitVersion();
QupZilla::QupZilla(bool tryRestore, QUrl startUrl) : QupZilla::QupZilla(bool tryRestore, QUrl startUrl) :
QMainWindow(0) QMainWindow(0)
,m_tryRestore(tryRestore) ,m_tryRestore(tryRestore)
,m_historyMenuChanged(true)
,m_startingUrl(startUrl) ,m_startingUrl(startUrl)
,m_actionPrivateBrowsing(0) ,m_actionPrivateBrowsing(0)
,m_webInspectorDock(0) ,m_webInspectorDock(0)
@ -359,6 +360,9 @@ void QupZilla::setupMenu()
menuBar()->setContextMenuPolicy(Qt::CustomContextMenu); menuBar()->setContextMenuPolicy(Qt::CustomContextMenu);
m_menuClosedTabs = new QMenu(tr("Closed Tabs"));
connect(m_menuClosedTabs, SIGNAL(aboutToShow()), this, SLOT(aboutToShowClosedTabsMenu()));
aboutToShowToolsMenu(); aboutToShowToolsMenu();
aboutToShowHelpMenu(); aboutToShowHelpMenu();
@ -501,8 +505,12 @@ void QupZilla::receiveMessage(MainApplication::MessageType mes, bool state)
LocationBarSettings::instance()->loadSettings(); LocationBarSettings::instance()->loadSettings();
break; break;
case MainApplication::StateChanged:
m_historyMenuChanged = true;
break;
default: default:
qWarning("Unresolved message sent!"); qWarning("Unresolved message sent! This could never happen!");
break; break;
} }
} }
@ -646,6 +654,11 @@ void QupZilla::aboutToShowHistoryMenu()
{ {
if (!weView()) if (!weView())
return; return;
if (!m_historyMenuChanged)
return;
m_historyMenuChanged = false;
m_menuHistory->clear(); m_menuHistory->clear();
m_menuHistory->addAction( m_menuHistory->addAction(
#ifdef Q_WS_X11 #ifdef Q_WS_X11
@ -689,7 +702,12 @@ void QupZilla::aboutToShowHistoryMenu()
m_menuHistory->addAction(_iconForUrl(url), title, this, SLOT(loadActionUrl()))->setData(url); m_menuHistory->addAction(_iconForUrl(url), title, this, SLOT(loadActionUrl()))->setData(url);
} }
m_menuHistory->addSeparator(); m_menuHistory->addSeparator();
QMenu* menuClosedTabs = new QMenu(tr("Closed Tabs")); m_menuHistory->addMenu(m_menuClosedTabs);
}
void QupZilla::aboutToShowClosedTabsMenu()
{
m_menuClosedTabs->clear();
int i = 0; int i = 0;
foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) { foreach (ClosedTabsManager::Tab tab, m_tabWidget->closedTabsManager()->allClosedTabs()) {
QString title = tab.title; QString title = tab.title;
@ -697,16 +715,14 @@ void QupZilla::aboutToShowHistoryMenu()
title.truncate(40); title.truncate(40);
title+=".."; 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++; i++;
} }
menuClosedTabs->addSeparator(); m_menuClosedTabs->addSeparator();
if (i == 0) if (i == 0)
menuClosedTabs->addAction(tr("Empty"))->setEnabled(false); m_menuClosedTabs->addAction(tr("Empty"))->setEnabled(false);
else else
menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs())); m_menuClosedTabs->addAction(tr("Restore All Closed Tabs"), m_tabWidget, SLOT(restoreAllClosedTabs()));
m_menuHistory->addMenu(menuClosedTabs);
} }
void QupZilla::aboutToShowHelpMenu() void QupZilla::aboutToShowHelpMenu()

View File

@ -148,6 +148,7 @@ private slots:
void aboutToShowHistoryBackMenu(); void aboutToShowHistoryBackMenu();
void aboutToShowHistoryNextMenu(); void aboutToShowHistoryNextMenu();
void aboutToShowHistoryMenu(); void aboutToShowHistoryMenu();
void aboutToShowClosedTabsMenu();
void aboutToShowBookmarksMenu(); void aboutToShowBookmarksMenu();
void aboutToShowToolsMenu(); void aboutToShowToolsMenu();
void aboutToShowHelpMenu(); void aboutToShowHelpMenu();
@ -197,6 +198,7 @@ private:
void setupMenu(); void setupMenu();
bool m_tryRestore; bool m_tryRestore;
bool m_historyMenuChanged;
QUrl m_startingUrl; QUrl m_startingUrl;
QUrl m_newtab; QUrl m_newtab;
QUrl m_homepage; QUrl m_homepage;
@ -210,6 +212,7 @@ private:
QMenu* m_menuView; QMenu* m_menuView;
QMenu* m_menuBookmarks; QMenu* m_menuBookmarks;
QMenu* m_menuHistory; QMenu* m_menuHistory;
QMenu* m_menuClosedTabs;
QMenu* m_menuBack; QMenu* m_menuBack;
QMenu* m_menuForward; QMenu* m_menuForward;
QMenu* m_menuEncoding; QMenu* m_menuEncoding;

View File

@ -46,6 +46,7 @@ DownloadItem::DownloadItem(QListWidgetItem* item, QNetworkReply* reply, QString
QFile::remove(fullPath); QFile::remove(fullPath);
m_outputFile.setFileName(fullPath); m_outputFile.setFileName(fullPath);
qDebug() << m_fileName << m_outputFile.fileName();
ui->setupUi(this); ui->setupUi(this);
setMaximumWidth(525); setMaximumWidth(525);

View File

@ -214,12 +214,12 @@ void DownloadManager::optionsDialogAccepted(int finish)
} }
} }
else else
fileNameChoosed(m_downloadPath + m_h_fileName); fileNameChoosed(m_downloadPath + m_h_fileName, true);
} else } 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; m_huserFileName = name;
if (m_huserFileName.isEmpty()) { if (m_huserFileName.isEmpty()) {
@ -236,6 +236,23 @@ void DownloadManager::fileNameChoosed(const QString &name)
m_hfileName = m_huserFileName.right(size-pos-1); 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())) if (!m_hpath.contains(QDir::tempPath()))
m_lastDownloadPath = m_hpath; m_lastDownloadPath = m_hpath;

View File

@ -73,7 +73,7 @@ private slots:
void optionsDialogAccepted(int finish); void optionsDialogAccepted(int finish);
void fileNameChoosed(const QString &name = ""); void fileNameChoosed(const QString &name, bool fileNameAutoGenerated = false);
signals: signals:
void resized(QSize); void resized(QSize);

View File

@ -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(siteIconChanged()), p_QupZilla->locationBar(), SLOT(siteIconChanged()));
// connect(weView(index), SIGNAL(showUrl(QUrl)), p_QupZilla->locationBar(), SLOT(showUrl(QUrl))); // connect(weView(index), SIGNAL(showUrl(QUrl)), p_QupZilla->locationBar(), SLOT(showUrl(QUrl)));
connect(webView, SIGNAL(wantsCloseTab(int)), this, SLOT(closeTab(int))); 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))); connect(webView, SIGNAL(ipChanged(QString)), p_QupZilla->ipLabel(), SLOT(setText(QString)));
if (url.isValid()) if (url.isValid())