diff options
Diffstat (limited to 'kftpgrabber/src/widgets/bookmarks')
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/Makefile.am | 13 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/editor.cpp | 492 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/editor.h | 133 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/editortls.cpp | 115 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/editortls.h | 85 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/importwizard.cpp | 167 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/importwizard.h | 85 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/listview.cpp | 532 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/listview.h | 193 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/sidebar.cpp | 158 | ||||
-rw-r--r-- | kftpgrabber/src/widgets/bookmarks/sidebar.h | 88 |
11 files changed, 2061 insertions, 0 deletions
diff --git a/kftpgrabber/src/widgets/bookmarks/Makefile.am b/kftpgrabber/src/widgets/bookmarks/Makefile.am new file mode 100644 index 0000000..d735a01 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(top_builddir)/kftpgrabber/src \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../../engine \ + -I$(srcdir)/../../misc \ + -I$(srcdir)/../../widgets \ + -I$(srcdir)/../../widgets/browser \ + -I$(srcdir)/../../ui \ + -I$(top_builddir)/kftpgrabber/src/ui \ + $(all_includes) +METASOURCES = AUTO +noinst_LIBRARIES = libbookmarkwidgets.a +noinst_HEADERS = editor.h editortls.h listview.h importwizard.h sidebar.h +libbookmarkwidgets_a_SOURCES = editor.cpp editortls.cpp listview.cpp importwizard.cpp sidebar.cpp diff --git a/kftpgrabber/src/widgets/bookmarks/editor.cpp b/kftpgrabber/src/widgets/bookmarks/editor.cpp new file mode 100644 index 0000000..88ba05c --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/editor.cpp @@ -0,0 +1,492 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2003-2004 by the KFTPGrabber developers + * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net> + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#include <qlayout.h> +#include <qpushbutton.h> +#include <qcheckbox.h> +#include <qgroupbox.h> +#include <qspinbox.h> +#include <qsplitter.h> +#include <qtextedit.h> +#include <qtabwidget.h> + +#include <kglobal.h> +#include <kcharsets.h> +#include <klocale.h> +#include <kiconloader.h> +#include <klineedit.h> +#include <kpassdlg.h> +#include <kmessagebox.h> +#include <kpopupmenu.h> +#include <kcombobox.h> +#include <kurlrequester.h> +#include <kguiitem.h> +#include <kfiledialog.h> +#include <kio/job.h> + +#include "kftpapi.h" +#include "kftpbookmarks.h" +#include "misc/config.h" +#include "misc.h" + +#include "editor.h" +#include "listview.h" +#include "importwizard.h" +#include "editortls.h" + +using namespace KFTPGrabberBase; + +namespace KFTPWidgets { + +namespace Bookmarks { + +KActionCollection *BookmarkEditor::actionCollection() +{ + return KFTPAPI::getInstance()->mainWindow()->actionCollection(); +} + +BookmarkEditor::BookmarkEditor(QWidget *parent, const char *name) + : KDialogBase(parent, name, true, "FTP Bookmark Editor", User2|User1|Ok|Apply|Cancel, Ok, true, KGuiItem(i18n("Import...")), KGuiItem(i18n("Export..."))), + m_activeSite(0), + m_activeItem(0L), + m_portChanged(false) +{ + // We operate on a copy of the bookmarks + m_bookmarks = new KFTPBookmarks::Manager(*KFTPBookmarks::Manager::self()); + + QHBoxLayout *winLayout = new QHBoxLayout(this, 0, KDialog::spacingHint()); + + QSplitter *splitter = new QSplitter(this); + setMainWidget(splitter); + winLayout->addWidget(splitter); + + // Create the list view for editing bookmarks + m_tree = new ListView(m_bookmarks, splitter); + + m_properties = new BookmarkProperties(splitter); + + initDialog(); + + connect(this, SIGNAL(user1Clicked()), this, SLOT(slotImportWizard())); + connect(this, SIGNAL(user2Clicked()), this, SLOT(slotExportWizard())); + + connect(m_tree, SIGNAL(bookmarkClicked(QListViewItem*)), this, SLOT(slotTreeClicked(QListViewItem*))); + connect(m_tree, SIGNAL(bookmarkNew(ListViewItem*, KFTPBookmarks::Site*)), this, SLOT(slotNewAction(ListViewItem*, KFTPBookmarks::Site*))); + connect(m_tree, SIGNAL(bookmarkDuplicated(ListViewItem*, KFTPBookmarks::Site*)), this, SLOT(slotDuplicateAction(ListViewItem*, KFTPBookmarks::Site*))); + connect(m_tree, SIGNAL(bookmarkDeleted()), this, SLOT(slotDeleteAction())); + connect(m_tree, SIGNAL(bookmarkMoved()), this, SLOT(refresh())); + connect(m_tree, SIGNAL(categoryRenamed()), this, SLOT(refresh())); + + // Get the new bookmark data + m_tree->fillBookmarkData(); +} + +BookmarkEditor::BookmarkEditor(ListViewItem *item, QWidget *parent, const char *name) + : KDialogBase(parent, name, true, i18n("FTP Bookmark Editor"), Ok|Apply|Cancel, Ok, true), + m_activeSite(0), + m_activeItem(item), + m_tree(0L), + m_portChanged(false) +{ + setCaption(m_activeItem->text(0)); + + // We operate on a copy of the bookmarks + m_bookmarks = new KFTPBookmarks::Manager(*KFTPBookmarks::Manager::self()); + + QHBoxLayout *winLayout = new QHBoxLayout(this, 0, KDialog::spacingHint()); + + m_properties = new BookmarkProperties(this); + setMainWidget(m_properties); + winLayout->addWidget(m_properties); + + initDialog(); + + m_activeSite = m_activeItem->m_site; + + showActiveNode(); +} + +BookmarkEditor::~BookmarkEditor() +{ + delete m_bookmarks; +} + +void BookmarkEditor::initDialog() +{ + m_properties->tabList->setTabIconSet(m_properties->general, loadSmallIcon("kfm")); + m_properties->tabList->setTabIconSet(m_properties->advanced, loadSmallIcon("contents")); + m_properties->tabList->setTabIconSet(m_properties->keepalive, loadSmallIcon("clock")); + m_properties->protoAdvanced->setIconSet(loadSmallIcon("configure")); + m_properties->retryGroup->setEnabled(false); + m_properties->defLocalDir->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly ); + + connect(m_properties->anonLogin, SIGNAL(clicked()), this, SLOT(slotChangeAnonLogin())); + connect(m_properties->doRetry, SIGNAL(clicked()), this, SLOT(slotChangeActiveRetryGroup())); + connect(m_properties->doKeepalive, SIGNAL(clicked()), this, SLOT(slotChangeActiveKeepaliveGroup())); + connect(m_properties->protoAdvanced, SIGNAL(clicked()), this, SLOT(slotProtoAdvancedClicked())); + connect(m_properties->serverProtocol, SIGNAL(activated(int)), this, SLOT(slotChangeServerProtocol(int))); + connect(m_properties->serverPort, SIGNAL(valueChanged(int)), this, SLOT(slotPortChanged())); + + connect(this, SIGNAL(applyClicked()), this, SLOT(slotSaveActiveNode())); + connect(this, SIGNAL(okClicked()), this, SLOT(slotSaveActiveNode())); + + // Populate charsets + QStringList charsets = KGlobal::charsets()->descriptiveEncodingNames(); + m_properties->serverEncoding->insertStringList(charsets); + + // Deactivate everything until an item gets selected + m_properties->setEnabled(false); +} + +void BookmarkEditor::refresh() +{ + m_tree->clear(); + m_tree->fillBookmarkData(); +} + +void BookmarkEditor::slotImportWizard() +{ + ImportWizard *wizard = new ImportWizard(this); + + if (wizard->exec() == QDialog::Accepted) { + // Refresh bookmarks + m_bookmarks->setBookmarks(KFTPBookmarks::Manager::self()); + + m_tree->clear(); + m_tree->fillBookmarkData(); + } + + delete wizard; +} + +void BookmarkEditor::slotExportWizard() +{ + if (KMessageBox::questionYesNo(0, i18n("<qt>You are about to export your KFTPGrabber bookmarks. They may contain passwords or sensitive X509 certificates; exporting your bookmarks may compromise their safety.<br><br>Are you sure?</qt>"), i18n("Export Bookmarks")) == KMessageBox::No) { + return; + } + + QString savePath = KFileDialog::getSaveFileName(QString::null, "*.xml|KFTPGrabber Bookmarks", 0, i18n("Export Bookmarks")); + + if (!savePath.isEmpty()) { + // Save and copy the bookmarks + KFTPBookmarks::Manager::self()->save(); + KIO::copy(KURL(getStoreDir("bookmarks.xml")), KURL(savePath), false); + } +} + +void BookmarkEditor::slotNewAction(ListViewItem *item, KFTPBookmarks::Site *site) +{ + // Display the new server's properties + m_activeItem = item; + m_activeSite = site; + + showActiveNode(); + + // Set Focus to servername + m_properties->serverName->selectAll(); + m_properties->serverName->setFocus(); +} + +void BookmarkEditor::slotDuplicateAction(ListViewItem *item, KFTPBookmarks::Site *site) +{ + m_activeItem = item; + + // Display its properties + m_activeSite = site; + + showActiveNode(); +} + +void BookmarkEditor::slotDeleteAction() +{ + m_activeItem = 0L; + m_properties->setEnabled(false); +} + +void BookmarkEditor::slotSaveActiveNode() +{ + if (!m_activeItem) { + KFTPBookmarks::Manager::self()->setBookmarks(m_bookmarks); + return; + } + + m_activeSite->setAttribute("name", m_properties->serverName->text()); + m_activeSite->setProperty("host", m_properties->serverAddress->text()); + m_activeSite->setProperty("port", m_properties->serverPort->value()); + m_activeSite->setProperty("protocol", m_properties->serverProtocol->currentItem() == SP_SFTP ? "sftp" : "ftp"); + m_activeSite->setProperty("use_tls", m_properties->serverProtocol->currentItem() == SP_SSL_EXPLICIT); + m_activeSite->setProperty("use_implicit", m_properties->serverProtocol->currentItem() == SP_SSL_IMPLICIT); + m_activeSite->setProperty("anonlogin", m_properties->anonLogin->isChecked()); + + m_activeSite->setProperty("username", m_properties->downUser->text()); + m_activeSite->setProperty("password", encodePassword(m_properties->downPass->password())); + + m_activeSite->setProperty("encoding", KGlobal::charsets()->encodingForName(m_properties->serverEncoding->currentText())); + + // Only save the local dir if it differs from the default one + if (m_properties->defLocalDir->url() != KFTPCore::Config::defLocalDir()) + m_activeSite->setProperty("deflocalpath", m_properties->defLocalDir->url()); + + m_activeSite->setProperty("defremotepath", m_properties->defRemoteDir->text()); + m_activeSite->setProperty("description", m_properties->description->text()); + + m_activeSite->setProperty("doRetry", m_properties->doRetry->isChecked()); + m_activeSite->setProperty("retrytime", m_properties->retryDelay->value()); + m_activeSite->setProperty("retrycount", m_properties->retryCount->value()); + + m_activeSite->setProperty("doKeepalive", m_properties->doKeepalive->isChecked()); + m_activeSite->setProperty("keepaliveTimeout", m_properties->keepaliveTimeout->value()); + + m_activeSite->setProperty("disablePASV", m_properties->disablePASV->isChecked()); + m_activeSite->setProperty("disableEPSV", m_properties->disableEPSV->isChecked()); + m_activeSite->setProperty("pasvSiteIp", m_properties->pasvSiteIp->isChecked()); + m_activeSite->setProperty("disableForceIp", m_properties->disableForceIp->isChecked()); + m_activeSite->setProperty("disableThreads", m_properties->threadsDisable->isChecked()); + m_activeSite->setProperty("statListings", m_properties->statListings->isChecked()); + + // Update the ListView node + m_activeItem->setText(0, m_properties->serverName->text()); + + if (m_tree) + KFTPBookmarks::Manager::self()->setBookmarks(m_bookmarks); + + showActiveNode(); + + // Save the bookmarks + KFTPBookmarks::Manager::self()->save(); +} + +void BookmarkEditor::showActiveNode() +{ + if (m_activeItem->m_type == BT_CATEGORY || !m_activeSite) { + m_properties->setEnabled(false); + return; + } + + m_properties->setEnabled(true); + + // Show all the data for the active node + m_properties->serverName->setText(m_activeSite->getAttribute("name")); + m_properties->serverAddress->setText(m_activeSite->getProperty("host")); + + if (m_activeSite->getProperty("protocol") == "sftp") m_properties->serverProtocol->setCurrentItem(SP_SFTP); + else if (m_activeSite->getIntProperty("use_tls")) m_properties->serverProtocol->setCurrentItem(SP_SSL_EXPLICIT); + else if (m_activeSite->getIntProperty("use_implicit")) m_properties->serverProtocol->setCurrentItem(SP_SSL_IMPLICIT); + else m_properties->serverProtocol->setCurrentItem(SP_FTP); + + slotChangeServerProtocol(m_properties->serverProtocol->currentItem()); + + + m_properties->serverPort->setValue(m_activeSite->getIntProperty("port")); + m_portChanged = false; + + m_properties->downUser->erase(); + m_properties->downPass->erase(); + m_properties->anonLogin->setChecked(m_activeSite->getIntProperty("anonlogin")); + + slotChangeAnonLogin(); + + m_properties->downUser->setText(m_activeSite->getProperty("username")); + m_properties->downPass->insert(m_activeSite->getProperty("password")); + + QString defLocalPath = m_activeSite->getProperty("deflocalpath"); + if (defLocalPath.isEmpty()) + defLocalPath = KFTPCore::Config::defLocalDir(); + + m_properties->defLocalDir->setURL(defLocalPath); + m_properties->defRemoteDir->setText(m_activeSite->getProperty("defremotepath")); + m_properties->description->setText(m_activeSite->getProperty("description")); + + int retryTime = m_activeSite->getIntProperty("retrytime"); + int retryCount = m_activeSite->getIntProperty("retrycount"); + + m_properties->doRetry->setChecked(m_activeSite->getIntProperty("doRetry")); + + if (m_properties->doRetry->isChecked()) { + m_properties->retryGroup->setEnabled(true); + m_properties->retryDelay->setValue(retryTime); + m_properties->retryCount->setValue(retryCount); + } else { + m_properties->retryGroup->setEnabled(false); + m_properties->retryDelay->setValue(KFTPCore::Config::retryTime()); + m_properties->retryCount->setValue(KFTPCore::Config::retryCount()); + } + + m_properties->doKeepalive->setChecked(m_activeSite->getIntProperty("doKeepalive")); + + if (m_properties->doKeepalive->isChecked()) { + m_properties->keepaliveGroup->setEnabled(true); + m_properties->keepaliveTimeout->setValue(m_activeSite->getIntProperty("keepaliveTimeout")); + } else { + m_properties->keepaliveGroup->setEnabled(false); + m_properties->keepaliveTimeout->setValue(60); + } + + QString serverEncoding = m_activeSite->getProperty("encoding"); + if (serverEncoding.isEmpty()) + serverEncoding = KFTPCore::Config::defEncoding(); + + serverEncoding = QString("%1 ( %2 )").arg(KGlobal::charsets()->languageForEncoding(serverEncoding)).arg(serverEncoding); + m_properties->serverEncoding->setCurrentText(serverEncoding); + + m_properties->disablePASV->setChecked(m_activeSite->getIntProperty("disablePASV")); + m_properties->disableEPSV->setChecked(m_activeSite->getIntProperty("disableEPSV")); + m_properties->pasvSiteIp->setChecked(m_activeSite->getIntProperty("pasvSiteIp")); + m_properties->disableForceIp->setChecked(m_activeSite->getIntProperty("disableForceIp")); + m_properties->threadsDisable->setChecked(m_activeSite->getIntProperty("disableThreads")); + m_properties->statListings->setChecked(m_activeSite->getIntProperty("statListings")); +} + +void BookmarkEditor::slotTreeClicked(QListViewItem *item) +{ + m_activeItem = static_cast<ListViewItem*>(item); + + if ( !m_activeItem || m_activeItem->m_type == BT_CATEGORY ) { + // Deactivate all controls + m_properties->setEnabled(false); + return; + } + + // Find the node and set it active + if (m_activeItem->m_type == BT_CATEGORY) { + // Category + m_activeSite = 0L; + } else { + // Server + m_activeSite = m_activeItem->m_site; + } + + // Show the active node (if any) + showActiveNode(); +} + +void BookmarkEditor::slotChangeActiveRetryGroup() +{ + m_properties->retryGroup->setEnabled(m_properties->doRetry->isChecked()); +} + +void BookmarkEditor::slotChangeActiveKeepaliveGroup() +{ + m_properties->keepaliveGroup->setEnabled(m_properties->doKeepalive->isChecked()); +} + +void BookmarkEditor::slotChangeAnonLogin() +{ + static QString tmpUser, tmpPass; + + if (m_properties->anonLogin->isChecked()) { + m_properties->downUser->setEnabled(false); + m_properties->downPass->setEnabled(false); + tmpUser = m_properties->downUser->text(); + tmpPass = m_properties->downPass->text(); + m_properties->downUser->setText("anonymous"); + + // Use the appropriate e-mail address for anonymous accounts + if (!KFTPCore::Config::anonMail().isEmpty()) + m_properties->downPass->setText(KFTPCore::Config::anonMail()); + else + m_properties->downPass->setText("userlogin@anonymo.us"); + } else { + m_properties->downUser->setEnabled(true); + m_properties->downPass->setEnabled(true); + m_properties->downUser->setText(tmpUser); + m_properties->downPass->setText(tmpPass); + } +} + +void BookmarkEditor::slotProtoAdvancedClicked() +{ + BookmarkEditorTLS *tlsDialog = new BookmarkEditorTLS(this); + + // Initialize dialog + int mode = m_activeSite->getIntProperty("tls_data_mode"); + bool useCert = m_activeSite->getIntProperty("use_cert"); + QString certPath = m_activeSite->getProperty("tls_cert_path"); + + tlsDialog->setTLSMode(mode); + tlsDialog->setCertChecked(useCert); + if (useCert) + tlsDialog->setCertPath(certPath); + tlsDialog->slotChangeActiveX509Group(); + + if (tlsDialog->exec()) { + // Save the modifications + m_activeSite->setProperty("tls_data_mode", tlsDialog->getTLSMode()); + m_activeSite->setProperty("use_cert", tlsDialog->isCertChecked()); + + if (tlsDialog->isCertChecked()) + m_activeSite->setProperty("tls_cert_path", tlsDialog->getCertPath()); + } + + delete tlsDialog; +} + +void BookmarkEditor::slotPortChanged() +{ + m_portChanged = true; +} + +void BookmarkEditor::slotChangeServerProtocol(int item) +{ + // Enable/Disable the SSL/TLS settings if needed + m_properties->protoAdvanced->setEnabled( item == 1 || item == 2 ); + + // Set the default port + if (!m_portChanged) { + switch (item) { + case SP_SSL_IMPLICIT: + if (m_properties->serverPort->value() == 21 || m_properties->serverPort->value() == 22) + m_properties->serverPort->setValue(993); + break; + case SP_SFTP: + if (m_properties->serverPort->value() == 21 || m_properties->serverPort->value() == 993) + m_properties->serverPort->setValue(22); + break; + default: + if (m_properties->serverPort->value() == 22 || m_properties->serverPort->value() == 993) + m_properties->serverPort->setValue(21); + break; + } + + m_portChanged = false; + } +} + +} + +} + +#include "editor.moc" diff --git a/kftpgrabber/src/widgets/bookmarks/editor.h b/kftpgrabber/src/widgets/bookmarks/editor.h new file mode 100644 index 0000000..50b04aa --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/editor.h @@ -0,0 +1,133 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2003-2004 by the KFTPGrabber developers + * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net> + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#ifndef KFTPBOOKMARKEDITOR_H +#define KFTPBOOKMARKEDITOR_H + +#include "ui/bookmark_properties.h" + +#include <kaction.h> +#include <kdialogbase.h> + +#include <qlistview.h> +#include <qdom.h> + +namespace KFTPBookmarks { + class Manager; + class Site; +} + +namespace KFTPWidgets { + +namespace Bookmarks { + +class ListViewItem; +class ListView; + +/** +@author Jernej Kos +*/ +class BookmarkEditor : public KDialogBase +{ +Q_OBJECT +public: + BookmarkEditor(QWidget *parent = 0, const char *name = 0); + BookmarkEditor(ListViewItem *item, QWidget *parent = 0, const char *name = 0); + ~BookmarkEditor(); +private: + enum BookmarkType { + BT_CATEGORY = 0, + BT_SERVER + }; + + enum ServerProtocol { + SP_FTP = 0, + SP_SSL_EXPLICIT, + SP_SSL_IMPLICIT, + SP_SFTP + }; + + KFTPBookmarks::Manager *m_bookmarks; + KFTPBookmarks::Site *m_activeSite; + + ListViewItem *m_activeItem; + + BookmarkProperties *m_properties; + ListView *m_tree; + + bool m_portChanged; + + /* Actions */ + KAction *m_newAction; + KAction *m_renameAction; + KAction *m_deleteAction; + KAction *m_subCatAction; + KAction *m_copyAction; + KActionCollection *actionCollection(); + + // Some common stuff for the constructors + void initDialog(); + + void showActiveNode(); +public slots: + void refresh(); +private slots: + /* Action slots */ + void slotNewAction(ListViewItem *item, KFTPBookmarks::Site *site); + void slotDeleteAction(); + void slotDuplicateAction(ListViewItem *item, KFTPBookmarks::Site *site); + + /* Other slots */ + void slotChangeAnonLogin(); + void slotProtoAdvancedClicked(); + void slotChangeActiveRetryGroup(); + void slotChangeActiveKeepaliveGroup(); + void slotChangeServerProtocol(int item); + void slotPortChanged(); + + void slotTreeClicked(QListViewItem *item); + + void slotImportWizard(); + void slotExportWizard(); + + void slotSaveActiveNode(); +}; + +} + +} + +#endif diff --git a/kftpgrabber/src/widgets/bookmarks/editortls.cpp b/kftpgrabber/src/widgets/bookmarks/editortls.cpp new file mode 100644 index 0000000..c299288 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/editortls.cpp @@ -0,0 +1,115 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2003-2004 by the KFTPGrabber developers + * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net> + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#include <qcheckbox.h> + +#include <kcombobox.h> +#include <klocale.h> +#include <kurlrequester.h> + +#include "kftpapi.h" +#include "editortls.h" +#include "kftpbookmarkeditortlswidget.h" +#include "misc.h" + +using namespace KFTPGrabberBase; + +namespace KFTPWidgets { + +namespace Bookmarks { + +KActionCollection *BookmarkEditorTLS::actionCollection() +{ + return KFTPAPI::getInstance()->mainWindow()->actionCollection(); +} + +BookmarkEditorTLS::BookmarkEditorTLS(QWidget *parent, const char *name) + : KDialogBase(parent, name) +{ + m_mainWidget = new KFTPBookmarkEditorTLSWidget(this); + setMainWidget(m_mainWidget); + + setCaption(i18n("SSL/TLS Settings")); + showButtonApply(false); + + connect(m_mainWidget->useCert, SIGNAL(clicked()), this, SLOT(slotChangeActiveX509Group())); +} + +BookmarkEditorTLS::~BookmarkEditorTLS() +{ + delete m_mainWidget; +} + +void BookmarkEditorTLS::slotChangeActiveX509Group() +{ + m_mainWidget->certPath->setEnabled(m_mainWidget->useCert->isChecked()); +} + +int BookmarkEditorTLS::getTLSMode() +{ + return m_mainWidget->tlsMode->currentItem(); +} + +bool BookmarkEditorTLS::isCertChecked() +{ + return m_mainWidget->useCert->isChecked(); +} + +QString BookmarkEditorTLS::getCertPath() +{ + return m_mainWidget->certPath->url(); +} + +void BookmarkEditorTLS::setTLSMode(int mode) +{ + m_mainWidget->tlsMode->setCurrentItem(mode); +} + +void BookmarkEditorTLS::setCertChecked(const bool checked) +{ + m_mainWidget->useCert->setChecked(checked); +} + +void BookmarkEditorTLS::setCertPath(const QString &path) +{ + m_mainWidget->certPath->setURL(path); +} + +} + +} + +#include "editortls.moc" diff --git a/kftpgrabber/src/widgets/bookmarks/editortls.h b/kftpgrabber/src/widgets/bookmarks/editortls.h new file mode 100644 index 0000000..3325946 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/editortls.h @@ -0,0 +1,85 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2003-2004 by the KFTPGrabber developers + * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net> + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#ifndef KFTPBOOKMARKEDITORTLS_H +#define KFTPBOOKMARKEDITORTLS_H + +#include "editor.h" +#include "kftpbookmarkeditortlswidget.h" + +#include <kaction.h> +#include <kdialogbase.h> + +#include <qlistview.h> +#include <qdom.h> + +namespace KFTPWidgets { + +namespace Bookmarks { + +/** +@author Jernej Kos +*/ +class BookmarkEditorTLS : public KDialogBase +{ +Q_OBJECT +public: + BookmarkEditorTLS(QWidget *parent = 0, const char *name = 0); + ~BookmarkEditorTLS(); + + int getTLSMode(); + bool isCertChecked(); + QString getCertPath(); + + void setTLSMode(int mode); + void setCertChecked(const bool checked); + void setCertPath(const QString &path); +private: + QDomNode m_activeNode; + QDomNode m_activeCategory; + + KFTPBookmarkEditorTLSWidget *m_mainWidget; + + KActionCollection *actionCollection(); +public slots: + void slotChangeActiveX509Group(); +}; + +} + +} + +#endif diff --git a/kftpgrabber/src/widgets/bookmarks/importwizard.cpp b/kftpgrabber/src/widgets/bookmarks/importwizard.cpp new file mode 100644 index 0000000..aa30bee --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/importwizard.cpp @@ -0,0 +1,167 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2003-2004 by the KFTPGrabber developers + * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#include "importwizard.h" +#include "kftpapi.h" +#include "kftppluginmanager.h" +#include "interfaces/kftpbookmarkimportplugin.h" +#include "misc.h" +#include "kftpbookmarks.h" + +#include <qfileinfo.h> +#include <qlabel.h> + +#include <kurlrequester.h> +#include <kmessagebox.h> +#include <klocale.h> +#include <kprogress.h> +#include <kstandarddirs.h> + +using namespace KFTPGrabberBase; + +namespace KFTPWidgets { + +namespace Bookmarks { + +PluginListItem::PluginListItem(KListView *parent, KService::Ptr service) + : KListViewItem(parent, service->name(), service->comment()), m_service(service) +{ + setPixmap(0, loadSmallPixmap("filter")); +} + +ImportWizard::ImportWizard(QWidget *parent, const char *name) + : KFTPBookmarkImportLayout(parent, name) +{ + m_pluginList->setFullWidth(true); + m_pluginList->setAllColumnsShowFocus(true); + + connect(m_pluginList, SIGNAL(clicked(QListViewItem*)), this, SLOT(slotPluginsSelectionChanged(QListViewItem*))); + + setNextEnabled(Step1, false); + + // Set pixmap + QString pixmapPath = locate("appdata", "kftpgrabber-bi-wizard.png"); + if (!pixmapPath.isNull()) { + QPixmap pix(pixmapPath); + + m_wizardPixmap->setPixmap(pix); + m_wizardPixmap_2->setPixmap(pix); + m_wizardPixmap_3->setPixmap(pix); + } + + // Disable useless help buttons + setHelpEnabled(Step1, false); + setHelpEnabled(Step2, false); + setHelpEnabled(Step3, false); + + displayPluginList(); +} + +void ImportWizard::next() +{ + if (currentPage() == Step1) { + // Load the plugin + m_plugin = KFTPAPI::getInstance()->pluginManager()->loadImportPlugin(m_service); + + if (!m_plugin) { + KMessageBox::error(0, i18n("Unable to load the selected import plugin.")); + return; + } else { + // Get the default plugin path + m_importUrl->setURL("~/" + m_plugin->getDefaultPath()); + } + } else if (currentPage() == Step2) { + // Check if the file exists + if (!QFileInfo(m_importUrl->url()).exists() || !QFileInfo(m_importUrl->url()).isReadable()) { + KMessageBox::error(0, i18n("The selected file does not exist or is not readable.")); + return; + } + } + + QWizard::next(); + + if (currentPage() == Step3) { + // Start the import + setBackEnabled(Step3, false); + + connect(m_plugin, SIGNAL(progress(int)), this, SLOT(slotImportProgress(int))); + m_plugin->import(m_importUrl->url()); + } +} + +void ImportWizard::slotImportProgress(int progress) +{ + m_progressBar->setProgress(progress); + + if (progress == 100) { + // Import complete + KMessageBox::information(0, i18n("Bookmark importing is complete.")); + + // Add the imported stuff to the current bookmarks + KFTPBookmarks::Manager::self()->importSites(m_plugin->getImportedXml().documentElement()); + + accept(); + } +} + +void ImportWizard::displayPluginList() +{ + KTrader::OfferList plugins = KFTPAPI::getInstance()->pluginManager()->getImportPlugins(); + + KTrader::OfferList::ConstIterator end(plugins.end()); + for (KTrader::OfferList::ConstIterator i(plugins.begin()); i != end; ++i) { + KService::Ptr service = *i; + + new PluginListItem(m_pluginList, service); + } +} + +void ImportWizard::slotPluginsSelectionChanged(QListViewItem *i) +{ + if (i) { + PluginListItem *item = static_cast<PluginListItem*>(i); + m_service = item->m_service; + + setNextEnabled(Step1, true); + } else { + setNextEnabled(Step1, false); + } +} + +} + +} + +#include "importwizard.moc" diff --git a/kftpgrabber/src/widgets/bookmarks/importwizard.h b/kftpgrabber/src/widgets/bookmarks/importwizard.h new file mode 100644 index 0000000..9b74dd3 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/importwizard.h @@ -0,0 +1,85 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2003-2004 by the KFTPGrabber developers + * Copyright (C) 2003-2004 Jernej Kos <kostko@jweb-network.net> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#ifndef KFTPBOOKMARKIMPORTWIZARD_H +#define KFTPBOOKMARKIMPORTWIZARD_H + +#include "kftpbookmarkimportlayout.h" + +#include <kparts/componentfactory.h> +#include <klistview.h> + +class KFTPBookmarkImportPlugin; + +namespace KFTPWidgets { + +namespace Bookmarks { + +class PluginListItem : public KListViewItem +{ +friend class ImportWizard; +public: + PluginListItem(KListView *parent, KService::Ptr service); +private: + KService::Ptr m_service; +}; + +/** + * This is a wizard used to import bookmarks via detected KParts plugins. + * + * @author Jernej Kos + */ +class ImportWizard : public KFTPBookmarkImportLayout +{ +Q_OBJECT +public: + ImportWizard(QWidget *parent = 0, const char *name = 0); +private: + KService::Ptr m_service; + KFTPBookmarkImportPlugin *m_plugin; + + void displayPluginList(); +private slots: + virtual void next(); + + void slotImportProgress(int progress); + void slotPluginsSelectionChanged(QListViewItem *i); +}; + +} + +} + +#endif diff --git a/kftpgrabber/src/widgets/bookmarks/listview.cpp b/kftpgrabber/src/widgets/bookmarks/listview.cpp new file mode 100644 index 0000000..4349604 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/listview.cpp @@ -0,0 +1,532 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2004 by the KFTPGrabber developers + * Copyright (C) 2004 Jernej Kos <kostko@jweb-network.net> + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#include "kftpapi.h" +#include "listview.h" +#include "kftpbookmarks.h" +#include "kftpsession.h" +#include "misc.h" + +#include <qdragobject.h> + +#include <kaction.h> +#include <kinputdialog.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kdebug.h> +#include <kio/passdlg.h> + +using namespace KFTPGrabberBase; + +namespace KFTPWidgets { + +namespace Bookmarks { + +ListViewItem::ListViewItem(QListView *parent, const QString &t1) + : KListViewItem(parent, t1) +{ +} + +ListViewItem::ListViewItem(QListViewItem *parent, const QString &t1) + : KListViewItem(parent, t1) +{ +} + +int ListViewItem::compare(QListViewItem *i, int col, bool) const +{ + if (m_type != static_cast<ListViewItem*>(i)->m_type) { + if (m_type == 0) + return -1; // category + else + return 1; // server + } + + return KListViewItem::compare(i, col, false); +} + +ListView::ListView(KFTPBookmarks::Manager *bookmarks, QWidget *parent, const char *name) + : KFTPWidgets::ListView(parent, name), + m_autoUpdate(false), + m_connectBookmark(false), + m_editMenuItem(false), + m_bookmarks(bookmarks), + m_activeSite(0), + m_activeCategory(0), + m_activeItem(0) +{ + // Set some stuff + setMinimumWidth(150); + setFullWidth(true); + addColumn(i18n("Bookmarks")); + setRootIsDecorated(true); + setEmptyListText(i18n("No bookmarks.")); + setItemsRenameable(false); + + // Drag & drop + setDragEnabled(true); + setAcceptDrops(true); + setDropVisualizer(false); + + // Init auto open timer + m_openTimer = new QTimer(this); + + connect(this, SIGNAL(dropped(QDropEvent*, QListViewItem*)), this, SLOT(slotDropped(QDropEvent*, QListViewItem*))); + connect(this, SIGNAL(clicked(QListViewItem*)), this, SLOT(slotClicked(QListViewItem*))); + connect(this, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(slotDoubleClicked(QListViewItem*))); + connect(this, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)), this, SLOT(slotContextMenu(QListViewItem*, const QPoint&, int))); + + /* Init the actions */ + m_newAction = new KAction(i18n("&New..."), "filenew", KShortcut(), this, SLOT(slotNewAction()), actionCollection(), "bookmark_new"); + m_renameAction = new KAction(i18n("&Rename"), KShortcut(), this, SLOT(slotRenameAction()), actionCollection(), "bookmark_rename"); + m_deleteAction = new KAction(i18n("&Delete"), "editdelete", KShortcut(), this, SLOT(slotDeleteAction()), actionCollection(), "bookmark_delete"); + m_subCatAction = new KAction(i18n("&Create Subcategory..."), "folder_new", KShortcut(), this, SLOT(slotSubCatAction()), actionCollection(), "bookmark_subcat"); + m_copyAction = new KAction(i18n("&Duplicate"), KShortcut(), this, SLOT(slotDuplicateAction()), actionCollection(), "bookmark_duplicate"); +} + +KActionCollection *ListView::actionCollection() +{ + return KFTPAPI::getInstance()->mainWindow()->actionCollection(); +} + +void ListView::setAutoUpdate(bool value) +{ + m_autoUpdate = value; + + if (value) + connect(m_bookmarks, SIGNAL(update()), this, SLOT(slotAutoUpdate())); + + slotAutoUpdate(); +} + +void ListView::setConnectBookmark(bool value) +{ + m_connectBookmark = value; + + if (value) + connect(this, SIGNAL(executed(QListViewItem*)), this, SLOT(slotBookmarkExecuted(QListViewItem*))); +} + +void ListView::setEditMenuItem(bool value) +{ + m_editMenuItem = value; +} + +void ListView::slotBookmarkExecuted(QListViewItem *item) +{ + if (!item || !m_connectBookmark || static_cast<ListViewItem*>(item)->m_type == BT_CATEGORY) + return; + + KFTPBookmarks::Site *site = static_cast<ListViewItem*>(item)->m_site; + KURL siteUrl = site->getUrl(); + + // Handle empty usernames and passwords for non-anonymous sites + if (!siteUrl.hasUser() || !siteUrl.hasPass() && siteUrl.user() != "anonymous") { + KIO::PasswordDialog *dlg = new KIO::PasswordDialog(i18n("Please provide your username and password for connecting to this site."), siteUrl.user(), true); + dlg->addCommentLine(i18n("Site:"), QString("%1:%2").arg(siteUrl.host()).arg(siteUrl.port())); + + if (dlg->exec() == KDialogBase::Accepted) { + siteUrl.setUser(dlg->username()); + siteUrl.setPass(dlg->password()); + + if (dlg->keepPassword()) { + // Save password to the bookmarked site + site->setProperty("username", dlg->username()); + site->setProperty("password", encodePassword(dlg->password())); + } + + delete dlg; + } else { + // Abort connection attempt + delete dlg; + return; + } + } + + // Just spawn a new session + KFTPSession::Session *session = KFTPSession::Manager::self()->spawnRemoteSession(KFTPSession::IgnoreSide, siteUrl, site); + m_bookmarks->setupClient(site, session->getClient()); +} + +void ListView::slotAutoUpdate() +{ + if (m_autoUpdate) { + // Update the bookmark list + fillBookmarkData(); + } +} + +QDragObject *ListView::dragObject() +{ + // Determine hotspot and pixmap + QPoint hotspot; + QPixmap pixmap = *selectedItem()->pixmap(0); + hotspot.setX(pixmap.width() / 2); + hotspot.setY(pixmap.height() / 2); + + QString id = static_cast<ListViewItem*>(selectedItem())->m_site->id(); + m_dragObject = new QStoredDrag("application/x-qlistviewitem", this); + QByteArray data; + QDataStream arg(data, IO_WriteOnly); + arg << id; + + // Start the drag + static_cast<QStoredDrag*>(m_dragObject)->setEncodedData(data); + m_dragObject->setPixmap(pixmap, hotspot); + + return m_dragObject; +} + +bool ListView::acceptDrag(QDropEvent *e) const +{ + // If it is a local drag, accept it + return e->source() == static_cast<QWidget*>(const_cast<ListView*>(this)); +} + +void ListView::contentsDragEnterEvent(QDragEnterEvent *e) +{ + if (!acceptDrag(e)) { + e->ignore(); + return; + } + e->acceptAction(); + + m_currentBeforeDropItem = selectedItem(); + QListViewItem *item = itemAt(contentsToViewport(e->pos())); + + if (item) { + m_dropItem = item; + m_openTimer->start(750); + } else { + m_dropItem = 0L; + } +} + +void ListView::contentsDragMoveEvent(QDragMoveEvent *e) +{ + if (!acceptDrag(e)) { + e->ignore(); + return; + } + e->acceptAction(); + + QListViewItem *item = itemAt(contentsToViewport(e->pos())); + if (item) { + setSelected(item, true); + if (item != m_dropItem) { + m_openTimer->stop(); + m_dropItem = item; + m_openTimer->start(750); + } + } else { + if (selectedItem()) { + setSelected(selectedItem(), false); + } + + m_openTimer->stop(); + m_dropItem = 0L; + } +} + +void ListView::contentsDragLeaveEvent(QDragLeaveEvent*) +{ + if (m_currentBeforeDropItem) { + setSelected(m_currentBeforeDropItem, true); + ensureItemVisible(m_currentBeforeDropItem); + } else { + setSelected(m_dropItem, false); + } + + m_openTimer->stop(); + m_dropItem = 0L; +} + +void ListView::slotOpenTimer() +{ + m_openTimer->stop(); + if (m_dropItem && m_dropItem->isExpandable()) { + // Expand the category + m_dropItem->setOpen(true); + } +} + +void ListView::slotDropped(QDropEvent *e, QListViewItem*) +{ + KFTPBookmarks::Site *parentSite = 0L; + + if (selectedItem()) { + QListViewItem *newParent = 0L; + + // Get the new path + if (static_cast<ListViewItem*>(selectedItem())->m_type == 0) + newParent = selectedItem(); + else + newParent = selectedItem()->parent(); + + if (newParent) + parentSite = static_cast<ListViewItem*>(newParent)->m_site; + else + parentSite = m_bookmarks->findCategory("root"); + } else { + parentSite = m_bookmarks->findCategory("root"); + } + + QString id; + + // Decode the data + QDataStream arg(e->encodedData("application/x-qlistviewitem"), IO_ReadOnly); + arg >> id; + + // Move the site + KFTPBookmarks::Site *originalSite = m_bookmarks->findSite(id); + parentSite->reparentSite(originalSite); + + emit bookmarkMoved(); + + // Notify the bookmark manager + m_bookmarks->emitUpdate(); +} + +void ListView::fillBookmarkData() +{ + // Fill the tree with data + m_bookmarks->guiPopulateBookmarksTree(this); +} + +void ListView::slotClicked(QListViewItem *item) +{ + m_activeItem = static_cast<ListViewItem*>(item); + + if (m_activeItem) { + if (m_activeItem->m_type == BT_CATEGORY) { + // Category + m_activeCategory = m_activeItem->m_site; + m_activeSite = 0L; + } else { + // Server + m_activeSite = m_activeItem->m_site; + m_activeCategory = m_activeSite->getParentSite(); + } + } + + emit bookmarkClicked(item); +} + +void ListView::slotDoubleClicked(QListViewItem *item) +{ + if (!item) + return; + + setOpen(item, !item->isOpen()); +} + +KFTPBookmarks::Manager *ListView::getBookmarks() +{ + return m_bookmarks; +} + +void ListView::slotRenameAction() +{ + // Rename a subcategory + ListViewItem *item = static_cast<ListViewItem*>(selectedItems().at(0)); + KFTPBookmarks::Site *site = item->m_site; + + bool ok; + QString newName = KInputDialog::getText(i18n("Category Name"), i18n("Rename category:"), item->text(0), &ok, this); + + if (ok) { + // Ok, let's rename it + site->setAttribute("name", newName); + item->setText(0, newName); + } +} + +void ListView::slotSubCatAction() +{ + // Create a subcategory + ListViewItem *item = static_cast<ListViewItem*>(selectedItems().at(0)); + KFTPBookmarks::Site *site = item ? item->m_site : m_bookmarks->findCategory("root"); + + bool ok; + QString newName = KInputDialog::getText(i18n("New Category Name"), i18n("New category:"), "", &ok, this); + + if (ok) { + // Let's create the sub category + site->addCategory(newName); + + emit categoryRenamed(); + m_bookmarks->emitUpdate(); + } +} + +void ListView::slotNewAction() +{ + if (!m_activeCategory) { + // Set the starting category to document root + m_activeCategory = m_bookmarks->findCategory("root"); + } + + // Create the new node + KFTPBookmarks::Site *site = m_activeCategory->addSite(); + site->setAttribute("name", i18n("New server")); + site->setProperty("port", 21); + + // Create the ListViewItem + ListViewItem *serv = 0L; + if (!m_activeItem || (!m_activeItem->parent() && m_activeItem->m_type == BT_SERVER)) { + serv = new ListViewItem(this, i18n("New Server")); + } else if (m_activeItem->m_type == BT_CATEGORY) { + serv = new ListViewItem(m_activeItem, i18n("New Server")); + m_activeItem->setOpen(true); + } else { + serv = new ListViewItem(m_activeItem->parent(), i18n("New Server")); + } + + serv->m_type = BT_SERVER; + serv->m_site = site; + + serv->setPixmap(0, loadSmallPixmap("ftp")); + + // Set the new ListViewItem as active + setSelected(serv, true); + m_activeItem = serv; + + // Display its properties + m_activeSite = site; + + emit bookmarkNew(serv, site); +} + +void ListView::slotDuplicateAction() +{ + // Copy a bookmark + ListViewItem *item = static_cast<ListViewItem*>(selectedItems().at(0)); + + // Clone the node + KFTPBookmarks::Site *copy = item->m_site->duplicate(); + + // Create the ListViewItem + ListViewItem *serv = 0L; + if (item->parent()) + serv = new ListViewItem(item->parent(), copy->getAttribute("name")); + else + serv = new ListViewItem(this, copy->getAttribute("name")); + + serv->m_type = BT_SERVER; + serv->m_site = copy; + + serv->setPixmap(0, loadSmallPixmap("ftp")); + + // Set the new ListViewItem as active + setSelected(serv, true); + m_activeItem = serv; + + // Display its properties + m_activeSite = copy; + + emit bookmarkDuplicated(serv, copy); + + // Update the bookmarks + m_bookmarks->emitUpdate(); +} + +void ListView::slotDeleteAction() +{ + // Delete a server or a category + ListViewItem *item = static_cast<ListViewItem*>(selectedItems().at(0)); + + // What do we have here ? + if (item->m_type == BT_CATEGORY) { + // Category + if (KMessageBox::questionYesNo(this, i18n("Are you sure you want to remove this category?")) == KMessageBox::Yes) { + m_bookmarks->delSite(item->m_site); + } else { + return; + } + } else { + // Server + if (KMessageBox::questionYesNo(this, i18n("Are you sure you want to remove this server?")) == KMessageBox::Yes) { + m_bookmarks->delSite(item->m_site); + } else { + return; + } + } + + if ( !m_autoUpdate ) + delete item; + + m_activeItem = 0L; + emit bookmarkDeleted(); +} + +void ListView::slotContextMenu(QListViewItem *item, const QPoint &pos, int) +{ + slotClicked(item); + + KPopupMenu *context = new KPopupMenu(this); + + if (item) { + context->insertTitle(item->text(0)); + + // Server or category + if (static_cast<ListViewItem*>(item)->m_type == BT_CATEGORY) { + m_newAction->plug(context); + m_deleteAction->plug(context); + m_subCatAction->plug(context); + m_renameAction->plug(context); + } else { + if (m_editMenuItem) + actionCollection()->action("bookmark_edit2")->plug(context); + + m_newAction->plug(context); + m_copyAction->plug(context); + m_deleteAction->plug(context); + } + } else { + // Nothing selected + m_newAction->plug(context); + m_subCatAction->plug(context); + } + + context->exec(pos); + + delete context; +} + +} + +} + +#include "listview.moc" diff --git a/kftpgrabber/src/widgets/bookmarks/listview.h b/kftpgrabber/src/widgets/bookmarks/listview.h new file mode 100644 index 0000000..213ec03 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/listview.h @@ -0,0 +1,193 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2004 by the KFTPGrabber developers + * Copyright (C) 2004 Jernej Kos <kostko@jweb-network.net> + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#ifndef KFTPBOOKMARKEDITORLISTVIEW_H +#define KFTPBOOKMARKEDITORLISTVIEW_H + +#include <qdom.h> +#include <qtimer.h> + +#include "../listview.h" + +class KAction; +class KActionCollection; +class Sidebar; +class KFTPSelectServerDialog; + +namespace KFTPBookmarks { + class Site; + class Manager; + class BookmarkEditor; + class Sidebar; +} + +namespace KFTPWidgets { + +namespace Bookmarks { + +class ListView; + +class ListViewItem : public KListViewItem +{ +friend class BookmarkEditor; +friend class KFTPWidgets::Bookmarks::ListView; +friend class Sidebar; +friend class ::KFTPSelectServerDialog; +public: + ListViewItem(QListView *parent, const QString &t1); + ListViewItem(QListViewItem *parent, const QString &t1); + + int compare(QListViewItem *i, int col, bool) const; + + void setSite(KFTPBookmarks::Site *site) { m_site = site; } + void setType(int type) { m_type = type; } +private: + int m_type; + KFTPBookmarks::Site *m_site; +}; + +/** +@author Jernej Kos +*/ +class ListView : public KFTPWidgets::ListView +{ +Q_OBJECT +public: + ListView(KFTPBookmarks::Manager *bookmarks, QWidget *parent = 0, const char *name = 0); + + /** + * Fill current treeview with all the bookmarks. + */ + void fillBookmarkData(); + + /** + * This changes the auto-update behaviour of the ListView. If set to true, this + * list view will automaticly update when bookmarks are changed. Defaults + * to false. + * + * @param value True to enable auto update, false otherwise + */ + void setAutoUpdate(bool value); + + /** + * This changes the connect-on-click behaviour of the ListView. If set to true, + * a new remote session will be spawned whenever the users double clicks the + * bookmark. + * + * @param value True to enable connect on click, false otherwise + */ + void setConnectBookmark(bool value); + + /** + * Get the bookmarks, the listview operates on + */ + KFTPBookmarks::Manager *getBookmarks(); + + /** + * Specifiy, whether an edit menuitem should be placed in the contextmenu + * + * @param value True to enable the edit menuitem, false otherwise + */ + void setEditMenuItem(bool value); + +private: + enum BookmarkType { + BT_CATEGORY = 0, + BT_SERVER + }; + + bool m_autoUpdate; + bool m_connectBookmark; + bool m_editMenuItem; + QDragObject *m_dragObject; + + /* Actions */ + KAction *m_newAction; + KAction *m_renameAction; + KAction *m_deleteAction; + KAction *m_subCatAction; + KAction *m_copyAction; + + /* Auto open categories support */ + QListViewItem *m_dropItem; + QListViewItem* m_currentBeforeDropItem; + QTimer *m_openTimer; + + /* Specifies, on which bookmarks we operate */ + KFTPBookmarks::Manager *m_bookmarks; + + KFTPBookmarks::Site *m_activeSite; + KFTPBookmarks::Site *m_activeCategory; + KFTPWidgets::Bookmarks::ListViewItem *m_activeItem; + + KActionCollection *actionCollection(); + + /* Drag & drop support */ + QDragObject *dragObject(); + bool acceptDrag(QDropEvent *e) const; + void contentsDragEnterEvent(QDragEnterEvent *e); + void contentsDragMoveEvent(QDragMoveEvent *e); + void contentsDragLeaveEvent(QDragLeaveEvent*); +private slots: + void slotDropped(QDropEvent *e, QListViewItem*); + void slotDoubleClicked(QListViewItem *item); + void slotOpenTimer(); + + void slotClicked(QListViewItem*); + void slotNewAction(); + void slotRenameAction(); + void slotDeleteAction(); + void slotSubCatAction(); + void slotDuplicateAction(); + void slotContextMenu(QListViewItem*, const QPoint&, int col); + + void slotAutoUpdate(); + void slotBookmarkExecuted(QListViewItem*); +signals: + void bookmarkMoved(); + void bookmarkNew(ListViewItem*, KFTPBookmarks::Site*); + void bookmarkDeleted(); + void bookmarkDuplicated(ListViewItem*, KFTPBookmarks::Site*); + void bookmarkClicked(QListViewItem*); + + void categoryRenamed(); +}; + +} + +} + +#endif diff --git a/kftpgrabber/src/widgets/bookmarks/sidebar.cpp b/kftpgrabber/src/widgets/bookmarks/sidebar.cpp new file mode 100644 index 0000000..21ee0d9 --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/sidebar.cpp @@ -0,0 +1,158 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2004 by the KFTPGrabber developers + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#include <qlayout.h> +#include <qsplitter.h> +#include <qvbox.h> + +#include <kaction.h> +#include <klocale.h> +#include <ktoolbar.h> + +#include "kftpapi.h" +#include "kftpbookmarks.h" +#include "editor.h" +#include "listview.h" +#include "misc.h" + +#include "sidebar.h" + +using namespace KFTPGrabberBase; + +namespace KFTPWidgets { + +namespace Bookmarks { + +KActionCollection *Sidebar::actionCollection() +{ + return KFTPAPI::getInstance()->mainWindow()->actionCollection(); +} + +Sidebar::Sidebar(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + + m_toolBar = new KToolBar(this, "bookmarkToolBar"); + m_toolBar->setIconSize(16); + layout->addWidget(m_toolBar); + + // Create the list view for editing bookmarks + m_tree = new ListView(KFTPBookmarks::Manager::self(), this); + m_tree->setAutoUpdate(true); + m_tree->setConnectBookmark(true); + m_tree->setEditMenuItem(true); + + layout->addWidget(m_tree); + + m_editAction = new KAction(i18n("&Edit..."), "edit", KShortcut(), this, SLOT(slotEditAction()), actionCollection(), "bookmark_edit2"); + connect(m_tree, SIGNAL(bookmarkClicked(QListViewItem*)), this, SLOT(slotClicked(QListViewItem*))); + connect(m_tree, SIGNAL(bookmarkNew(ListViewItem*, KFTPBookmarks::Site*)), this, SLOT(slotNewAction(ListViewItem*, KFTPBookmarks::Site*))); + + // Get the new bookmark data + m_tree->fillBookmarkData(); + + // Init the Actions + slotClicked(0L); + + setMinimumWidth(200); +} + +Sidebar::~Sidebar() +{ +} + +void Sidebar::refresh() +{ + m_tree->clear(); + m_tree->fillBookmarkData(); +} + +void Sidebar::slotEditAction() +{ + ListViewItem* item = static_cast<ListViewItem*>(m_tree->selectedItems().at(0)); + + if (item) { + BookmarkEditor *editor = new BookmarkEditor(item, this); + + editor->exec(); + delete editor; + + // Update the bookmarks globaly + KFTPBookmarks::Manager::self()->emitUpdate(); + } +} + +void Sidebar::slotNewAction(ListViewItem*, KFTPBookmarks::Site *site) +{ + BookmarkEditor *editor = new BookmarkEditor(static_cast<ListViewItem*>(m_tree->selectedItems().at(0)), this); + + if (!editor->exec()) { + // If the user clicks Abort, remove the newly created server + KFTPBookmarks::Manager::self()->delSite(site); + } + + delete editor; +} + +void Sidebar::slotClicked(QListViewItem *item) +{ + // When nodes are expanded, item is 0, although an item is still selected, so grab it here + item = m_tree->selectedItems().at(0); + + // Enable/Disable actions for the toolbar + if (!item) { + actionCollection()->action("bookmark_delete")->setEnabled(false); + actionCollection()->action("bookmark_subcat")->setEnabled(true); + m_editAction->setEnabled(false); + return; + } + + actionCollection()->action("bookmark_delete")->setEnabled(true); + + if (static_cast<ListViewItem*>(item)->m_type == BT_CATEGORY) { + m_editAction->setEnabled(false); + actionCollection()->action("bookmark_subcat")->setEnabled(true); + } else { + m_editAction->setEnabled(true); + actionCollection()->action("bookmark_subcat")->setEnabled(false); + } +} + +} + +} + +#include "sidebar.moc" diff --git a/kftpgrabber/src/widgets/bookmarks/sidebar.h b/kftpgrabber/src/widgets/bookmarks/sidebar.h new file mode 100644 index 0000000..ef08d3e --- /dev/null +++ b/kftpgrabber/src/widgets/bookmarks/sidebar.h @@ -0,0 +1,88 @@ +/* + * This file is part of the KFTPGrabber project + * + * Copyright (C) 2004 by the KFTPGrabber developers + * Copyright (C) 2004 Markus Brueffer <markus@brueffer.de> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and + * NON-INFRINGEMENT. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ + +#ifndef KFTPBOOKMARKSIDEBAR_H +#define KFTPBOOKMARKSIDEBAR_H + +namespace KFTPBookmarks { + class Site; +} + +class KAction; +class KToolBar; + +namespace KFTPWidgets { + +namespace Bookmarks { + +class ListViewItem; +class ListView; + +/** +@author Markus Brueffer +*/ +class Sidebar : public QWidget +{ +Q_OBJECT +public: + Sidebar(QWidget *parent = 0, const char *name = 0); + ~Sidebar(); + +private: + enum BookmarkType { + BT_CATEGORY = 0, + BT_SERVER + }; + + KToolBar *m_toolBar; + ListView *m_tree; + + KAction *m_editAction; + KActionCollection *actionCollection(); +public slots: + void refresh(); +private slots: + void slotClicked(QListViewItem*); + + /* Action slots */ + void slotEditAction(); + void slotNewAction(ListViewItem *item, KFTPBookmarks::Site *site); +}; + +} + +} + +#endif |