From 50fd11d4a7718f36263d39e1d716ad33d28b3e89 Mon Sep 17 00:00:00 2001 From: lappelhans Date: Sun, 27 Jan 2008 00:06:00 +0000 Subject: [PATCH] First bits of the new GroupSettings-Dialog: *DefaultFolders per group ---> already implemented *SpeedLimits per group ---> will follow the next days... git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/KDE/kdenetwork@766945 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kget/CMakeLists.txt | 2 + kget/core/kget.cpp | 32 +++++++++ kget/core/kget.h | 5 ++ kget/core/transfergroup.cpp | 13 +++- kget/core/transfergroup.h | 51 ++++++++++++++ kget/core/transfergrouphandler.cpp | 2 + kget/core/transfergrouphandler.h | 46 ++++++++++++ kget/core/transfertreemodel.cpp | 4 +- kget/mainwindow.cpp | 19 +++++ kget/mainwindow.h | 1 + kget/ui/groupsettingsdialog.cpp | 58 +++++++++++++++ kget/ui/groupsettingsdialog.h | 39 ++++++++++ kget/ui/groupsettingsdialog.ui | 141 +++++++++++++++++++++++++++++++++++++ kget/ui/newtransferdialog.cpp | 63 ++++++----------- kget/ui/newtransferdialog.h | 4 +- 15 files changed, 435 insertions(+), 45 deletions(-) create mode 100644 kget/ui/groupsettingsdialog.cpp create mode 100644 kget/ui/groupsettingsdialog.h create mode 100644 kget/ui/groupsettingsdialog.ui diff --git a/kget/CMakeLists.txt b/kget/CMakeLists.txt index c89f9def4..64187425d 100644 --- a/kget/CMakeLists.txt +++ b/kget/CMakeLists.txt @@ -71,6 +71,7 @@ set(kget_SRCS ${kget_adaptor_SRCS} ui/newtransferdialog.cpp ui/transferhistory.cpp ui/rangetreewidget.cpp + ui/groupsettingsdialog.cpp mainwindow.cpp main.cpp ) @@ -83,6 +84,7 @@ kde4_add_ui_files(kget_SRCS ui/transferdetailsfrm.ui ui/newtransferwidget.ui ui/transferhistory.ui + ui/groupsettingsdialog.ui ) kde4_add_executable(kget ${kget_SRCS}) diff --git a/kget/core/kget.cpp b/kget/core/kget.cpp index 8b74b2354..31a5482d6 100644 --- a/kget/core/kget.cpp +++ b/kget/core/kget.cpp @@ -551,6 +551,38 @@ void KGet::reloadKJobs() m_jobManager->reload(); } +QStringList KGet::defaultFolders(const KUrl &filename, const QString &groupname) +{ + kDebug(5001) << filename << groupname; + + QStringList list; + if (Settings::enableExceptions()) + list.append(KGet::getSaveDirectoryFromExceptions(filename)); + + TransferGroup * group = KGet::m_transferTreeModel->findGroup(groupname); + + if (!group->defaultFolder().isEmpty()) + list.append(group->defaultFolder()); + + if (Settings::useDefaultDirectory()) + list.append(Settings::defaultDirectory()); + + if (!Settings::lastDirectory().isEmpty() && + QString::compare(Settings::lastDirectory(), Settings::defaultDirectory()) != 0) + list.append(Settings::lastDirectory()); + + foreach(QString string, list) + { +#ifdef Q_OS_WIN //krazy:exclude=cpp + string.remove("file:///"); +#else + string.remove("file://"); +#endif + } + + return list; +} + // ------ STATIC MEMBERS INITIALIZATION ------ QList KGet::m_observers; TransferTreeModel * KGet::m_transferTreeModel; diff --git a/kget/core/kget.h b/kget/core/kget.h index cbbe1dde2..9a50ee35c 100644 --- a/kget/core/kget.h +++ b/kget/core/kget.h @@ -245,6 +245,11 @@ class KGET_EXPORT KGet static void unregisterKJob(KJob *); static void reloadKJobs(); + /** + * @return a list of the defaultFolders for a transfer + */ + static QStringList defaultFolders(const KUrl &filename, const QString &groupname); + private: KGet(); ~KGet(); diff --git a/kget/core/transfergroup.cpp b/kget/core/transfergroup.cpp index 51bfe7d98..402cf68c3 100644 --- a/kget/core/transfergroup.cpp +++ b/kget/core/transfergroup.cpp @@ -29,7 +29,9 @@ TransferGroup::TransferGroup(TransferTreeModel * model, Scheduler * scheduler, c : JobQueue(scheduler), m_model(model), m_handler(0), m_name(name), m_totalSize(0), m_processedSize(0), - m_percent(0), m_speed(0) + m_percent(0), m_speed(0), + m_dlLimit(0), m_ulLimit(0), + m_iconName("bookmark-new-list"), m_defaultFolder(0) { } @@ -199,6 +201,10 @@ void TransferGroup::save(QDomElement e) // krazy:exclude=passbyvalue kDebug(5001) << "TransferGroup::save() --> " << name(); e.setAttribute("Name", m_name); + e.setAttribute("Default_folder", m_defaultFolder); + e.setAttribute("Download_Limit", m_dlLimit); + e.setAttribute("Upload_Limit", m_ulLimit); + e.setAttribute("Icon", m_iconName); iterator it = begin(); iterator itEnd = end(); @@ -217,6 +223,11 @@ void TransferGroup::load(const QDomElement & e) kDebug(5001) << "TransferGroup::load"; m_name = e.attribute("Name"); + m_defaultFolder = e.attribute("Default_folder"); + m_dlLimit = e.attribute("Download_Limit").toInt(); + m_ulLimit = e.attribute("Upload_Limit").toInt(); + if (!e.attribute("Icon").isEmpty()) + m_iconName = e.attribute("Icon"); QDomNodeList nodeList = e.elementsByTagName("Transfer"); int nItems = nodeList.length(); diff --git a/kget/core/transfergroup.h b/kget/core/transfergroup.h index 1ef341ce7..8ef53468b 100644 --- a/kget/core/transfergroup.h +++ b/kget/core/transfergroup.h @@ -13,6 +13,7 @@ #define GROUP_H #include +#include #include "jobqueue.h" #include "kget_export.h" @@ -159,6 +160,52 @@ class KGET_EXPORT TransferGroup : public JobQueue int speed() const {return m_speed;} /** + * Set a default Folder for the group + * @param folder the new default folder + */ + void setDefaultFolder(QString folder) {m_defaultFolder = folder;} + + /** + * @return the groups default folder + */ + QString defaultFolder() {return m_defaultFolder;} + + /** + * Set a Download-Limit for the group + * @param limit the new download-limit + * @note if limit is 0, no download-limit is set + */ + void setDownloadLimit(int limit) {m_dlLimit = limit;} + + /** + * @return the group's Download-Limit + */ + int downloadLimit() {return m_dlLimit;} + + /** + * Set a Upload-Limit for the group + * @param limit the new upload-limit + * @note if limit is 0, no upload-limit is set + */ + void setUploadLimit(int limit) {m_ulLimit = limit;} + + /** + * @return the group's Upload-Limit + */ + int uploadLimit() {return m_ulLimit;} + + /** + * Set the group's icon + * @param name the icon's name + */ + void setIconName(QString name) {m_iconName = name;} + + /** + * @return the group's icon + */ + QPixmap pixmap() {return KIcon(m_iconName).pixmap(32);} + + /** * @return the handler associated with this group */ TransferGroupHandler * handler(); @@ -199,6 +246,10 @@ class KGET_EXPORT TransferGroup : public JobQueue int m_processedSize; int m_percent; int m_speed; + int m_dlLimit; + int m_ulLimit; + QString m_iconName; + QString m_defaultFolder; }; #endif diff --git a/kget/core/transfergrouphandler.cpp b/kget/core/transfergrouphandler.cpp index bcbe3023f..f5e8149df 100644 --- a/kget/core/transfergrouphandler.cpp +++ b/kget/core/transfergrouphandler.cpp @@ -184,6 +184,8 @@ KMenu * TransferGroupHandler::popupMenu() popup->addAction( KGet::actionCollection()->action("transfer_group_start") ); popup->addAction( KGet::actionCollection()->action("transfer_group_stop") ); + popup->addSeparator(); + popup->addAction(KGet::actionCollection()->action("transfer_group_settings")); if(m_group->name() != i18n("My Downloads")) { popup->addSeparator(); popup->addAction( KGet::actionCollection()->action("delete_groups") ); diff --git a/kget/core/transfergrouphandler.h b/kget/core/transfergrouphandler.h index c5e504ed8..b9e6d8036 100644 --- a/kget/core/transfergrouphandler.h +++ b/kget/core/transfergrouphandler.h @@ -120,6 +120,52 @@ class KGET_EXPORT TransferGroupHandler int speed() const {return m_group->speed();} /** + * Set a default Folder for the group + * @param folder the new default folder + */ + void setDefaultFolder(QString folder) {m_group->setDefaultFolder(folder);} + + /** + * @return the groups default folder + */ + QString defaultFolder() {return m_group->defaultFolder();} + + /** + * Set a Download-Limit for the group + * @param limit the new download-limit + * @note if limit is 0, no download-limit is set + */ + void setDownloadLimit(int limit) {m_group->setDownloadLimit(limit);} + + /** + * @return the group's Download-Limit + */ + int downloadLimit() {return m_group->downloadLimit();} + + /** + * Set a Upload-Limit for the group + * @param limit the new upload-limit + * @note if limit is 0, no upload-limit is set + */ + void setUploadLimit(int limit) {m_group->setUploadLimit(limit);} + + /** + * @return the group's Upload-Limit + */ + int uploadLimit() {return m_group->uploadLimit();} + + /** + * Set the group's icon + * @param name the icon's name + */ + void setIconName(QString name) {m_group->setIconName(name);} + + /** + * @return the group's icon + */ + QPixmap pixmap() {return m_group->pixmap();} + + /** * @returns the data associated to this TransferGroup item. This is * necessary to make the interview model/view work */ diff --git a/kget/core/transfertreemodel.cpp b/kget/core/transfertreemodel.cpp index 0e0b6190c..92162bf0a 100644 --- a/kget/core/transfertreemodel.cpp +++ b/kget/core/transfertreemodel.cpp @@ -336,17 +336,17 @@ QVariant TransferTreeModel::data(const QModelIndex & index, int role) const if(isTransferGroup(index)) { + TransferGroupHandler * group = static_cast(pointer); if (role == Qt::DisplayRole) { // kDebug(5001) << " (GROUP)"; //The given index refers to a group object - TransferGroupHandler * group = static_cast(pointer); return group->data(index.column()); } else //Qt::DecorationRole -> icon { if (index.column() == 0) - return SmallIcon("bookmark-new-list", 32); + return group->pixmap(); else return QVariant(); } diff --git a/kget/mainwindow.cpp b/kget/mainwindow.cpp index 3bf6107cf..f5bb6b877 100644 --- a/kget/mainwindow.cpp +++ b/kget/mainwindow.cpp @@ -5,6 +5,7 @@ Copyright (C) 2002 Carsten Pfeiffer Copyright (C) 2006, 2007 Urs Wolfer Copyright (C) 2006 Dario Massarin + Copyright (C) 2008 Lukas Appelhans This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public @@ -25,6 +26,7 @@ #include "ui/droptarget.h" #include "ui/newtransferdialog.h" #include "ui/transferhistory.h" +#include "ui/groupsettingsdialog.h" #include #include @@ -239,6 +241,12 @@ void MainWindow::setupActions() transferHistoryAction->setIcon(KIcon("view-history")); transferHistoryAction->setShortcuts(KShortcut("Ctrl+H")); connect(transferHistoryAction, SIGNAL(triggered()), SLOT(slotTransferHistory())); + + QAction *transferGroupSettingsAction = actionCollection()->addAction("transfer_group_settings"); + transferGroupSettingsAction->setText(i18n("&Group Settings")); + transferGroupSettingsAction->setIcon(KIcon("preferences-system")); + transferGroupSettingsAction->setShortcuts(KShortcut("Ctrl+G")); + connect(transferGroupSettingsAction, SIGNAL(triggered()), SLOT(slotTransferGroupSettings())); } void MainWindow::slotDelayedInit() @@ -616,6 +624,17 @@ void MainWindow::slotTransferHistory() history->exec(); } +void MainWindow::slotTransferGroupSettings() +{ + kDebug(5001); + QList list = KGet::selectedTransferGroups(); + foreach(TransferGroupHandler* group, list) + { + GroupSettingsDialog *settings = new GroupSettingsDialog(this, group); + settings->exec(); + } +} + /** widget events */ void MainWindow::closeEvent( QCloseEvent * e ) diff --git a/kget/mainwindow.h b/kget/mainwindow.h index 47c70cb58..ec7c4a974 100644 --- a/kget/mainwindow.h +++ b/kget/mainwindow.h @@ -80,6 +80,7 @@ private slots: void slotTrayKonquerorIntegration(bool); void slotKonquerorIntegration( bool ); void slotShowMenubar(); + void slotTransferGroupSettings(); // transfers slots void slotStopAllDownload(); diff --git a/kget/ui/groupsettingsdialog.cpp b/kget/ui/groupsettingsdialog.cpp new file mode 100644 index 000000000..17177a0ba --- /dev/null +++ b/kget/ui/groupsettingsdialog.cpp @@ -0,0 +1,58 @@ +/* This file is part of the KDE project + + Copyright (C) 2008 Lukas Appelhans + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. +*/ +#include "groupsettingsdialog.h" + +#include "core/transfergrouphandler.h" + +GroupSettingsDialog::GroupSettingsDialog(QWidget *parent, TransferGroupHandler *group) + : KDialog(parent), + m_group(group) +{ + setCaption(i18n("Group-Settings for %1", group->name())); + QWidget *widget = new QWidget(this); + Ui::GroupSettingsDialog ui; + ui.setupUi(widget); + setMainWidget(widget); + m_downloadBox = ui.downloadBox; + m_downloadBox->setValue(group->downloadLimit()); + m_uploadBox = ui.uploadBox; + m_uploadBox->setValue(group->uploadLimit()); + m_downloadCheck = ui.downloadCheck; + if (m_downloadBox->value() != 0) + m_downloadCheck->setChecked(true); + m_uploadCheck = ui.uploadCheck; + if (m_uploadBox->value() != 0) + m_uploadCheck->setChecked(true); + m_defaultFolderRequester = ui.defaultFolderRequester; + m_defaultFolderRequester->setMode(KFile::Directory); + m_defaultFolderRequester->setPath(group->defaultFolder()); + connect(this, SIGNAL(accepted()), SLOT(save())); +} + +GroupSettingsDialog::~GroupSettingsDialog() +{ +} + +void GroupSettingsDialog::save() +{ + m_group->setDefaultFolder(m_defaultFolderRequester->url().path()); + + if (m_downloadCheck->isChecked()) + m_group->setDownloadLimit(m_downloadBox->value()); + else + m_group->setDownloadLimit(0); + + if (m_uploadCheck->isChecked()) + m_group->setUploadLimit(m_uploadBox->value()); + else + m_group->setUploadLimit(0); +} + +#include "groupsettingsdialog.moc" diff --git a/kget/ui/groupsettingsdialog.h b/kget/ui/groupsettingsdialog.h new file mode 100644 index 000000000..54221ce6f --- /dev/null +++ b/kget/ui/groupsettingsdialog.h @@ -0,0 +1,39 @@ +/* This file is part of the KDE project + + Copyright (C) 2008 Lukas Appelhans + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. +*/ +#ifndef GROUPSETTINGSDIALOG_H +#define GROUPSETTINGSDIALOG_H + +#include "ui_groupsettingsdialog.h" + +#include + +class TransferGroupHandler; + +class GroupSettingsDialog : public KDialog +{ + Q_OBJECT + public: + GroupSettingsDialog(QWidget *parent, TransferGroupHandler *group); + ~GroupSettingsDialog(); + + private slots: + void save(); + + private: + TransferGroupHandler* m_group; + + QCheckBox *m_downloadCheck; + QCheckBox *m_uploadCheck; + QSpinBox *m_downloadBox; + QSpinBox *m_uploadBox; + KUrlRequester *m_defaultFolderRequester; +}; + +#endif diff --git a/kget/ui/groupsettingsdialog.ui b/kget/ui/groupsettingsdialog.ui new file mode 100644 index 000000000..913b4a216 --- /dev/null +++ b/kget/ui/groupsettingsdialog.ui @@ -0,0 +1,141 @@ + + GroupSettingsDialog + + + + 0 + 0 + 415 + 149 + + + + Form + + + Qt::LeftToRight + + + + + + true + + + + + + + Group-Settings + + + + + + + Max download Speed + + + + + + + false + + + + 0 + 0 + + + + KiB + + + 10000 + + + + + + + Max upload Speed + + + + + + + false + + + + 0 + 0 + + + + KiB + + + 10000 + + + + + + + Default folder: + + + + + + + + KTitleWidget + QWidget +
ktitlewidget.h
+
+ + KUrlRequester + QFrame +
kurlrequester.h
+
+
+ + + + downloadCheck + toggled(bool) + downloadBox + setEnabled(bool) + + + 87 + 95 + + + 205 + 95 + + + + + uploadCheck + toggled(bool) + uploadBox + setEnabled(bool) + + + 87 + 122 + + + 205 + 122 + + + + +
diff --git a/kget/ui/newtransferdialog.cpp b/kget/ui/newtransferdialog.cpp index 28c2d4ff9..5ea5eff18 100644 --- a/kget/ui/newtransferdialog.cpp +++ b/kget/ui/newtransferdialog.cpp @@ -100,6 +100,8 @@ void NewTransferDialog::setSource(const QString &srcUrl) if (m_srcUrl.isValid()) urlRequester->insert(m_srcUrl.url()); + + connect(urlRequester, SIGNAL(textChanged(const QString &)), SLOT(setDestination())); } void NewTransferDialog::setSource(const KUrl::List &list) @@ -136,13 +138,22 @@ KUrl::List NewTransferDialog::source() const return list; } -void NewTransferDialog::setDestination(const QString &destination) +void NewTransferDialog::setDestination() { - if (!QUrl(destination).isValid()) - return; + QString filename = KUrl(destination()).fileName(); + if (filename.isEmpty()) + filename = source().first().fileName(); - m_destRequester->comboBox()->insertItem(0, destination); - m_destRequester->comboBox()->setCurrentIndex(0); + foreach(QString url, KGet::defaultFolders(source().first().path(), transferGroup())) + { + if (KUrl(url).isValid() && !m_destRequester->comboBox()->contains(url + filename))//FIXME: The last check doesn't work :( + { + if (multiple()) + m_destRequester->comboBox()->addUrl(url); + else + m_destRequester->comboBox()->addUrl(url + '/' + filename); + } + } } QString NewTransferDialog::destination() const @@ -158,43 +169,11 @@ QString NewTransferDialog::transferGroup() const void NewTransferDialog::showNewTransferDialog(NewTransferDialog *dialog) { QString destDir; - - if (Settings::useDefaultDirectory()) -#ifdef Q_OS_WIN //krazy:exclude=cpp - destDir = Settings::defaultDirectory().remove("file:///"); -#else - destDir = Settings::defaultDirectory().remove("file://"); -#endif - - if (!dialog->source().isEmpty()) - { - QString checkExceptions = KGet::getSaveDirectoryFromExceptions(dialog->source().first()); - - if (Settings::enableExceptions() && !checkExceptions.isEmpty()) - { - destDir = checkExceptions; - } - } - - if (!Settings::lastDirectory().isEmpty() && - QString::compare(Settings::lastDirectory(), Settings::defaultDirectory()) != 0) - { - if (dialog->multiple()) - dialog->setDestination(Settings::lastDirectory()); - else - dialog->setDestination(Settings::lastDirectory() + '/' + dialog->source().first().fileName()); - } - - if (!destDir.isEmpty()) - { - if (dialog->multiple()) - dialog->setDestination(destDir); - else - dialog->setDestination(destDir + '/' + dialog->source().first().fileName()); - } - if (dialog->destination().isEmpty()) - dialog->setDestination(QDir::home().path() + '/' + dialog->source().first().fileName()); + dialog->setDestination(); + + //if (dialog->destination().isEmpty()) + // dialog->setDestination(QDir::home().path() + '/' + dialog->source().first().fileName()); dialog->exec(); @@ -252,6 +231,8 @@ void NewTransferDialog::prepareGui() m_groupComboBox->setCurrentIndex(0); m_titleWidget->setPixmap(KIcon("document-new").pixmap(22, 22), KTitleWidget::ImageLeft); + + connect(m_groupComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setDestination())); } #include "newtransferdialog.moc" diff --git a/kget/ui/newtransferdialog.h b/kget/ui/newtransferdialog.h index 15111f62a..d84091ff8 100644 --- a/kget/ui/newtransferdialog.h +++ b/kget/ui/newtransferdialog.h @@ -32,13 +32,15 @@ public: void setSource(const QString &srcUrl = QString()); void setSource(const KUrl::List &list); KUrl::List source() const; - void setDestination(const QString &destUrl); QString destination() const; QString transferGroup() const; void setMultiple(bool multiple); bool multiple() const; +public slots: + void setDestination(); + private: static void showNewTransferDialog(NewTransferDialog *dialog); void prepareGui(); -- 2.11.4.GIT