]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Places Panel: Provide dialog for editing places
authorPeter Penz <peter.penz19@gmail.com>
Thu, 26 Apr 2012 21:39:48 +0000 (23:39 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 26 Apr 2012 21:41:01 +0000 (23:41 +0200)
src/CMakeLists.txt
src/panels/places/placesitemeditdialog.cpp [new file with mode: 0644]
src/panels/places/placesitemeditdialog.h [new file with mode: 0644]
src/panels/places/placesitemmodel.cpp
src/panels/places/placesitemmodel.h
src/panels/places/placespanel.cpp
src/panels/places/placespanel.h

index 4d87ee0bf87f2980c284d4c589d1316af7d5048e..7af27606100174a848e76ec562697196ea002be9 100644 (file)
@@ -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 (file)
index 0000000..dd7ac85
--- /dev/null
@@ -0,0 +1,158 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   Based on KFilePlaceEditDialog from kdelibs:                           *
+ *   Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>      *
+ *   Copyright (C) 2007 Kevin Ottens <ervin@kde.org>                       *                                                                         *
+ *                                                                         *
+ *   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 <KAboutData>
+#include <KComponentData>
+#include <KFile>
+#include <KIconButton>
+#include <KLineEdit>
+#include <KLocale>
+#include <KMimeType>
+#include <KUrlRequester>
+#include <QCheckBox>
+#include <QEvent>
+#include <QFormLayout>
+#include <QVBoxLayout>
+
+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 (file)
index 0000000..eddde54
--- /dev/null
@@ -0,0 +1,73 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   Based on KFilePlaceEditDialog from kdelibs:                           *
+ *   Copyright (C) 2001,2002,2003 Carsten Pfeiffer <pfeiffer@kde.org>      *
+ *   Copyright (C) 2007 Kevin Ottens <ervin@kde.org>                       *                                                                         *
+ *                                                                         *
+ *   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 <KDialog>
+#include <KUrl>
+
+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
index 219c766985741ce81c610b689c3710964f252272..f3162e7b24f53f4360ae5d6976323155049e4023 100644 (file)
@@ -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();
index 635ad116c79ef460a6025d4676b73573105de695..91678eee5ea58f473bdd25fde72a82b65c5ed2ec 100644 (file)
@@ -30,6 +30,7 @@
 #include <QSet>
 
 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();
 
index 016a736de62e4b863454bb66be3a75ce89d4f26d..d42b75f5a81caa915e7a3c793727866a304763f6 100644 (file)
 #include "placespanel.h"
 
 #include <KConfigGroup>
+#include <KDirNotify>
 #include <KIcon>
+#include <KIO/Job>
+#include <KIO/JobUiDelegate>
 #include <KLocale>
 #include <kitemviews/kitemlistcontainer.h>
 #include <kitemviews/kitemlistcontroller.h>
 #include <kitemviews/kstandarditemlistview.h>
 #include <KMenu>
+#include <KMessageBox>
+#include <KNotification>
+#include "placesitemeditdialog.h"
 #include "placesitemlistgroupheader.h"
 #include "placesitemmodel.h"
 #include <views/draganddrophelper.h>
@@ -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>() == 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<PlacesItemEditDialog> 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<QByteArray, QVariant> data = m_model->data(index);
+
+    QPointer<PlacesItemEditDialog> 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<KUrl>());
+    dialog->setAllowGlobal(true);
+    if (dialog->exec() == QDialog::Accepted) {
+        // TODO
+    }
+
+    delete dialog;
+}
+
 #include "placespanel.moc"
index 5758d287935e1105893c3ca336d026d78f3fdbc3..c9ea7ba048cef94d0bcfcf811430ae3226df3584 100644 (file)
@@ -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;