From: Peter Penz Date: Thu, 26 Apr 2012 21:39:48 +0000 (+0200) Subject: Places Panel: Provide dialog for editing places X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/d1c5dc52a3ac4f83262d00d37a61f6bfb52d5bf4?ds=sidebyside Places Panel: Provide dialog for editing places --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d87ee0bf..7af276061 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -143,6 +143,7 @@ set(dolphin_SRCS panels/information/pixmapviewer.cpp panels/information/phononwidget.cpp panels/places/placespanel.cpp + panels/places/placesitemeditdialog.cpp panels/places/placesitemlistgroupheader.cpp panels/places/placesitemmodel.cpp panels/panel.cpp diff --git a/src/panels/places/placesitemeditdialog.cpp b/src/panels/places/placesitemeditdialog.cpp new file mode 100644 index 000000000..dd7ac85a5 --- /dev/null +++ b/src/panels/places/placesitemeditdialog.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * Copyright (C) 2012 by Peter Penz * + * * + * Based on KFilePlaceEditDialog from kdelibs: * + * Copyright (C) 2001,2002,2003 Carsten Pfeiffer * + * Copyright (C) 2007 Kevin Ottens * * + * * + * 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 WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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 Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "placesitemeditdialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +PlacesItemEditDialog::PlacesItemEditDialog(QWidget* parent) : + KDialog(parent), + m_icon(), + m_text(), + m_url(), + m_allowGlobal(false), + m_urlEdit(0), + m_textEdit(0), + m_iconButton(0), + m_appLocal(0) +{ + setButtons( Ok | Cancel ); + setModal(true); + setDefaultButton(Ok); +} + +void PlacesItemEditDialog::setIcon(const QString& icon) +{ + m_icon = icon; +} + +QString PlacesItemEditDialog::icon() const +{ + return m_icon; +} + +void PlacesItemEditDialog::setText(const QString& text) +{ + m_text = text; +} + +QString PlacesItemEditDialog::text() const +{ + return m_text; +} + +void PlacesItemEditDialog::setUrl(const KUrl& url) +{ + m_url = url; +} + +KUrl PlacesItemEditDialog::url() const +{ + return m_url; +} + +void PlacesItemEditDialog::setAllowGlobal(bool allow) +{ + m_allowGlobal = allow; +} + +bool PlacesItemEditDialog::allowGlobal() const +{ + return m_allowGlobal; +} + +bool PlacesItemEditDialog::event(QEvent* event) +{ + if (event->type() == QEvent::Polish) { + initialize(); + } + return QWidget::event(event); +} + +PlacesItemEditDialog::~PlacesItemEditDialog() +{ +} + +void PlacesItemEditDialog::initialize() +{ + QWidget* mainWidget = new QWidget(this); + QVBoxLayout* vBox = new QVBoxLayout(mainWidget); + + QFormLayout* formLayout = new QFormLayout(); + vBox->addLayout( formLayout ); + + m_textEdit = new KLineEdit(mainWidget); + formLayout->addRow(i18nc("@label", "Label:"), m_textEdit); + m_textEdit->setText(m_text); + m_textEdit->setClickMessage(i18n("Enter descriptive label here")); + + m_urlEdit = new KUrlRequester(m_url.prettyUrl(), mainWidget); + m_urlEdit->setMode(KFile::Directory); + formLayout->addRow(i18nc("@label", "Location:"), m_urlEdit); + // Provide room for at least 40 chars (average char width is half of height) + m_urlEdit->setMinimumWidth(m_urlEdit->fontMetrics().height() * (40 / 2)); + + m_iconButton = new KIconButton(mainWidget); + formLayout->addRow(i18nc("@label", "Choose an icon:"), m_iconButton); + m_iconButton->setIconSize(KIconLoader::SizeLarge); + m_iconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Place); + if (m_icon.isEmpty()) { + m_iconButton->setIcon(KMimeType::iconNameForUrl(m_url)); + } else { + m_iconButton->setIcon(m_icon); + } + + if (m_allowGlobal) { + QString appName; + if (KGlobal::mainComponent().aboutData()) { + appName = KGlobal::mainComponent().aboutData()->programName(); + } + if (appName.isEmpty()) { + appName = KGlobal::mainComponent().componentName(); + } + m_appLocal = new QCheckBox( i18n("&Only show when using this application (%1)", appName ), mainWidget ); + m_appLocal->setChecked(false); + vBox->addWidget(m_appLocal); + } + + if (m_text.isEmpty()) { + m_urlEdit->setFocus(); + } else { + m_textEdit->setFocus(); + } + + setMainWidget( mainWidget ); +} + +#include "placesitemeditdialog.moc" diff --git a/src/panels/places/placesitemeditdialog.h b/src/panels/places/placesitemeditdialog.h new file mode 100644 index 000000000..eddde5430 --- /dev/null +++ b/src/panels/places/placesitemeditdialog.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2012 by Peter Penz * + * * + * Based on KFilePlaceEditDialog from kdelibs: * + * Copyright (C) 2001,2002,2003 Carsten Pfeiffer * + * Copyright (C) 2007 Kevin Ottens * * + * * + * 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 WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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 Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef PLACESITEMEDITDIALOG_H +#define PLACESITEMEDITDIALOG_H + +#include +#include + +class KIconButton; +class KLineEdit; +class KUrlRequester; +class QCheckBox; + +class PlacesItemEditDialog: public KDialog +{ + Q_OBJECT + +public: + explicit PlacesItemEditDialog(QWidget* parent = 0); + virtual ~PlacesItemEditDialog(); + + void setIcon(const QString& icon); + QString icon() const; + + void setText(const QString& text); + QString text() const; + + void setUrl(const KUrl& url); + KUrl url() const; + + void setAllowGlobal(bool allow); + bool allowGlobal() const; + +protected: + virtual bool event(QEvent* event); + +private: + void initialize(); + +private: + QString m_icon; + QString m_text; + KUrl m_url; + bool m_allowGlobal; + + KUrlRequester* m_urlEdit; + KLineEdit* m_textEdit; + KIconButton* m_iconButton; + QCheckBox* m_appLocal; +}; + +#endif diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 219c76698..f3162e7b2 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -66,6 +66,23 @@ PlacesItemModel::~PlacesItemModel() { } +int PlacesItemModel::hiddenCount() const +{ + return 0; +} + +QAction* PlacesItemModel::ejectAction(int index) const +{ + Q_UNUSED(index); + return 0; +} + +QAction* PlacesItemModel::tearDownAction(int index) const +{ + Q_UNUSED(index); + return 0; +} + void PlacesItemModel::loadBookmarks() { KBookmarkGroup root = m_bookmarkManager->root(); diff --git a/src/panels/places/placesitemmodel.h b/src/panels/places/placesitemmodel.h index 635ad116c..91678eee5 100644 --- a/src/panels/places/placesitemmodel.h +++ b/src/panels/places/placesitemmodel.h @@ -30,6 +30,7 @@ #include class KBookmarkManager; +class QAction; #ifdef HAVE_NEPOMUK namespace Nepomuk @@ -49,6 +50,11 @@ public: explicit PlacesItemModel(QObject* parent = 0); virtual ~PlacesItemModel(); + int hiddenCount() const; + + QAction* ejectAction(int index) const; + QAction* tearDownAction(int index) const; + private: void loadBookmarks(); diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 016a736de..d42b75f5a 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -24,12 +24,18 @@ #include "placespanel.h" #include +#include #include +#include +#include #include #include #include #include #include +#include +#include +#include "placesitemeditdialog.h" #include "placesitemlistgroupheader.h" #include "placesitemmodel.h" #include @@ -111,28 +117,63 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) KMenu menu(this); - QAction* emptyTrash = 0; - QAction* addEntry = 0; + QAction* emptyTrashAction = 0; + QAction* addAction = 0; QAction* mainSeparator = 0; - QAction* editEntry = 0; - QAction* hideEntry = 0; + QAction* editAction = 0; + QAction* tearDownAction = 0; + QAction* ejectAction = 0; const bool isDevice = !data.value("udi").toString().isEmpty(); if (isDevice) { + ejectAction = m_model->ejectAction(index); + if (ejectAction) { + ejectAction->setParent(&menu); + menu.addAction(ejectAction); + } + + tearDownAction = m_model->tearDownAction(index); + if (tearDownAction) { + tearDownAction->setParent(&menu); + menu.addAction(tearDownAction); + } + + if (tearDownAction || ejectAction) { + mainSeparator = menu.addSeparator(); + } } else { if (data.value("url").value() == KUrl("trash:/")) { - emptyTrash = menu.addAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash")); + emptyTrashAction = menu.addAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash")); KConfig trashConfig("trashrc", KConfig::SimpleConfig); - emptyTrash->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); + emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); menu.addSeparator(); } - addEntry = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + addAction = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); mainSeparator = menu.addSeparator(); - editEntry = menu.addAction(KIcon("document-properties"), i18n("&Edit Entry '%1'...", label)); + editAction = menu.addAction(KIcon("document-properties"), i18nc("@item:inmenu", "Edit Entry '%1'...", label)); } - if (!addEntry) { - addEntry = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + if (!addAction) { + addAction = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + } + + QAction* hideAction = menu.addAction(i18nc("@item:inmenu", "Hide Entry '%1'", label)); + hideAction->setCheckable(true); + //hideEntry->setChecked(data.value("hidden").toBool()); + + QAction* showAllAction = 0; + if (m_model->hiddenCount() > 0) { + if (!mainSeparator) { + mainSeparator = menu.addSeparator(); + } + showAllAction = menu.addAction(i18nc("@item:inmenu", "Show All Entries")); + showAllAction->setCheckable(true); + //showAllEntries->setChecked(showAll) + } + + QAction* removeAction = 0; + if (!isDevice) { + removeAction = menu.addAction(KIcon("edit-delete"), i18nc("@item:inmenu", "Remove Entry '%1'", label)); } menu.addSeparator(); @@ -141,25 +182,38 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) } QAction* action = menu.exec(pos.toPoint()); - hideEntry = menu.addAction(i18n("&Hide Entry '%1'", label)); - hideEntry->setCheckable(true); - //hideEntry->setChecked(data.value("hidden").toBool()); - Q_UNUSED(action); + if (!action) { + return; + } + + if (action == emptyTrashAction) { + emptyTrash(); + } else if (action == addAction) { + addEntry(); + } else if (action == editAction) { + editEntry(index); + } else if (action == removeAction) { + } else if (action == hideAction) { + } else if (action == showAllAction) { + } else if (action == tearDownAction) { + } else if (action == ejectAction) { + } } void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos) { KMenu menu(this); - QAction* addEntry = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); + QAction* addAction = menu.addAction(KIcon("document-new"), i18nc("@item:inmenu", "Add Entry...")); menu.addSeparator(); foreach (QAction* action, customContextMenuActions()) { menu.addAction(action); } QAction* action = menu.exec(pos.toPoint()); - Q_UNUSED(action); - Q_UNUSED(addEntry); + if (action == addAction) { + addEntry(); + } } void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent) @@ -168,4 +222,61 @@ void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* DragAndDropHelper::dropUrls(KFileItem(), dest, event); } +void PlacesPanel::slotTrashUpdated(KJob* job) +{ + if (job->error()) { + // TODO: Show error-string inside Dolphin, don't use job->ui->showErrorMessage(). + } + org::kde::KDirNotify::emitFilesAdded("trash:/"); +} + +void PlacesPanel::emptyTrash() +{ + const QString text = i18nc("@info", "Do you really want to empty the Trash? All items will be deleted."); + const bool del = KMessageBox::warningContinueCancel(window(), + text, + QString(), + KGuiItem(i18nc("@action:button", "Empty Trash"), + KIcon("user-trash")) + ) == KMessageBox::Continue; + if (del) { + QByteArray packedArgs; + QDataStream stream(&packedArgs, QIODevice::WriteOnly); + stream << int(1); + KIO::Job *job = KIO::special(KUrl("trash:/"), packedArgs); + KNotification::event("Trash: emptied", QString() , QPixmap() , 0, KNotification::DefaultEvent); + job->ui()->setWindow(parentWidget()); + connect(job, SIGNAL(result(KJob*)), SLOT(slotTrashUpdated(KJob*))); + } +} + +void PlacesPanel::addEntry() +{ + QPointer dialog = new PlacesItemEditDialog(this); + dialog->setCaption(i18nc("@title:window", "Add Places Entry")); + dialog->setAllowGlobal(true); + if (dialog->exec() == QDialog::Accepted) { + // TODO + } + + delete dialog; +} + +void PlacesPanel::editEntry(int index) +{ + const QHash data = m_model->data(index); + + QPointer dialog = new PlacesItemEditDialog(this); + dialog->setCaption(i18nc("@title:window", "Edit Places Entry")); + dialog->setIcon(data.value("iconName").toString()); + dialog->setText(data.value("text").toString()); + dialog->setUrl(data.value("url").value()); + dialog->setAllowGlobal(true); + if (dialog->exec() == QDialog::Accepted) { + // TODO + } + + delete dialog; +} + #include "placespanel.moc" diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h index 5758d2879..c9ea7ba04 100644 --- a/src/panels/places/placespanel.h +++ b/src/panels/places/placespanel.h @@ -54,6 +54,12 @@ private slots: void slotItemContextMenuRequested(int index, const QPointF& pos); void slotViewContextMenuRequested(const QPointF& pos); void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent); + void slotTrashUpdated(KJob* job); + +private: + void emptyTrash(); + void addEntry(); + void editEntry(int index); private: KItemListController* m_controller;