1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42: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)
{
if (event->timerId() == m_timer.timerId() && mApp->isChanged())
if (event->timerId() == m_timer.timerId() && mApp->isStateChanged())
emit saveApp();
else
QObject::timerEvent(event);

View File

@ -55,7 +55,7 @@ MainApplication::MainApplication(const QList<CommandLineOptions::ActionPair> &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;

View File

@ -55,7 +55,7 @@ public:
QString DATADIR;
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 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<MainApplication*>(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;
};

View File

@ -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()

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

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(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())