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
--- /dev/null
+/***************************************************************************
+ * 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"
--- /dev/null
+/***************************************************************************
+ * 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
{
}
+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();
#include <QSet>
class KBookmarkManager;
+class QAction;
#ifdef HAVE_NEPOMUK
namespace Nepomuk
explicit PlacesItemModel(QObject* parent = 0);
virtual ~PlacesItemModel();
+ int hiddenCount() const;
+
+ QAction* ejectAction(int index) const;
+ QAction* tearDownAction(int index) const;
+
private:
void loadBookmarks();
#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>
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();
}
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)
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"
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;