diff --git a/src/gui/listdevices.cpp b/src/gui/listdevices.cpp new file mode 100644 index 0000000..2bae0f2 --- /dev/null +++ b/src/gui/listdevices.cpp @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (C) 2008,2009 by Volker Lanz * + * * + * 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 "gui/listdevices.h" + +#include "gui/partitionmanagerwidget.h" + +#include "core/device.h" + +#include "util/globallog.h" +#include "util/capacity.h" + +#include +#include + +/** Creates a new ListDevices instance. + @param parent the parent widget +*/ +ListDevices::ListDevices(QWidget* parent) : + QWidget(parent), + Ui::ListDevicesBase(), + m_ActionCollection(NULL), + m_PartitionManagerWidget(NULL) +{ + setupUi(this); +} + +void ListDevices::updateDevices() +{ + int idx = listDevices().currentRow(); + + listDevices().clear(); + + foreach(const Device* d, pmWidget().previewDevices()) + { + const QString shortText = d->deviceNode() + " (" + Capacity(*d).toString() + ')'; + const QString longText = d->deviceNode() + " (" + Capacity(*d).toString() + ", " + d->name() + ')'; + QListWidgetItem* item = new QListWidgetItem(DesktopIcon(d->iconName()), shortText); + item->setToolTip(longText); + item->setSizeHint(QSize(0, 32)); + listDevices().addItem(item); + } + + if (idx > -1 && idx < listDevices().count()) + listDevices().setCurrentRow(idx); +} + +void ListDevices::on_m_ListDevices_itemSelectionChanged() +{ + int idx = -1; + + if (listDevices().selectedItems().size() == 1) + idx = listDevices().row(listDevices().selectedItems()[0]); + + Device* d = NULL; + if (idx >= 0 && idx < pmWidget().previewDevices().size()) + d = pmWidget().previewDevices()[idx]; + + emit selectionChanged(d); +} + +void ListDevices::on_m_ListDevices_customContextMenuRequested(const QPoint& pos) +{ + Q_ASSERT(actionCollection()); + + KMenu deviceMenu; + deviceMenu.addAction(actionCollection()->action("createNewPartitionTable")); + deviceMenu.exec(listDevices().viewport()->mapToGlobal(pos)); +} diff --git a/src/gui/listdevices.h b/src/gui/listdevices.h new file mode 100644 index 0000000..8e758f0 --- /dev/null +++ b/src/gui/listdevices.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2008,2009 by Volker Lanz * + * * + * 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 * + ***************************************************************************/ + +#if !defined(LISTDEVICES__H) + +#define LISTDEVICES__H + +#include "util/libpartitionmanagerexport.h" + +#include "ui_listdevicesbase.h" + +#include + +#include + +class Device; +class QPoint; +class PartitionManagerWidget; +class KActionCollection; + +/** @brief A list of devices. + @author vl@fidra.de +*/ +class LIBPARTITIONMANAGERPRIVATE_EXPORT ListDevices : public QWidget, public Ui::ListDevicesBase +{ + Q_OBJECT + Q_DISABLE_COPY(ListDevices) + + public: + ListDevices(QWidget* parent); + + signals: + void selectionChanged(Device*); + + public: + void init(KActionCollection* coll, PartitionManagerWidget* pm_widget) { m_ActionCollection = coll; m_PartitionManagerWidget = pm_widget; } + + public slots: + void updateDevices(); + + protected: + QListWidget& listDevices() { Q_ASSERT(m_ListDevices); return *m_ListDevices; } + const QListWidget& listDevices() const { Q_ASSERT(m_ListDevices); return *m_ListDevices; } + + PartitionManagerWidget& pmWidget() { Q_ASSERT(m_PartitionManagerWidget); return *m_PartitionManagerWidget; } + const PartitionManagerWidget& pmWidget() const { Q_ASSERT(m_PartitionManagerWidget); return *m_PartitionManagerWidget; } + + KActionCollection* actionCollection() { return m_ActionCollection; } + + protected slots: + void on_m_ListDevices_itemSelectionChanged(); + void on_m_ListDevices_customContextMenuRequested(const QPoint& pos); + + private: + KActionCollection* m_ActionCollection; + PartitionManagerWidget* m_PartitionManagerWidget; +}; + +#endif + diff --git a/src/gui/listdevicesbase.ui b/src/gui/listdevicesbase.ui new file mode 100644 index 0000000..81e8959 --- /dev/null +++ b/src/gui/listdevicesbase.ui @@ -0,0 +1,37 @@ + + + ListDevicesBase + + + + 0 + 0 + 255 + 396 + + + + + + + + 0 + 0 + + + + Qt::CustomContextMenu + + + + 32 + 32 + + + + + + + + + diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 9d6ab3b..181ffd5 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -61,6 +61,7 @@ void MainWindow::init() setupStatusBar(); setupConnections(); + listDevices().init(actionCollection(), &pmWidget()); listOperations().init(actionCollection(), &pmWidget()); pmWidget().init(actionCollection(), "partitionmanagerrc"); @@ -123,6 +124,7 @@ void MainWindow::setupActions() KStandardAction::quit(this, SLOT(close()), actionCollection()); // View actions + actionCollection()->addAction("toggleDockDevices", dockDevices().toggleViewAction()); actionCollection()->addAction("toggleDockOperations", dockOperations().toggleViewAction()); actionCollection()->addAction("toggleDockInformation", dockInformation().toggleViewAction()); actionCollection()->addAction("toggleDockLog", dockLog().toggleViewAction()); @@ -166,6 +168,8 @@ void MainWindow::updateStatusBar() void MainWindow::updateDevices() { + listDevices().updateDevices(); + if (pmWidget().selectedDevice()) infoPane().showDevice(dockWidgetArea(&dockInformation()), *pmWidget().selectedDevice()); else @@ -174,6 +178,12 @@ void MainWindow::updateDevices() updateWindowTitle(); } +void MainWindow::on_m_ListDevices_selectionChanged(Device* d) +{ + pmWidget().setSelectedDevice(d); + updateSelection(NULL); +} + void MainWindow::onDockLocationChanged(Qt::DockWidgetArea) { updateSelection(pmWidget().selectedPartition()); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 4953e33..af79f50 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -62,6 +62,9 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT MainWindow : public KXmlGuiWindow, publi PartitionManagerWidget& pmWidget() { Q_ASSERT(m_PartitionManagerWidget); return *m_PartitionManagerWidget; } const PartitionManagerWidget& pmWidget() const { Q_ASSERT(m_PartitionManagerWidget); return *m_PartitionManagerWidget; } + ListDevices& listDevices() { Q_ASSERT(m_ListDevices); return *m_ListDevices; } + const ListDevices& listDevices() const { Q_ASSERT(m_ListDevices); return *m_ListDevices; } + ListOperations& listOperations() { Q_ASSERT(m_ListOperations); return *m_ListOperations; } const ListOperations& listOperations() const { Q_ASSERT(m_ListOperations); return *m_ListOperations; } @@ -71,6 +74,9 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT MainWindow : public KXmlGuiWindow, publi QDockWidget& dockInformation() { Q_ASSERT(m_DockInformation); return *m_DockInformation; } const QDockWidget& dockInformation() const { Q_ASSERT(m_DockInformation); return *m_DockInformation; } + QDockWidget& dockDevices() { Q_ASSERT(m_DockDevices); return *m_DockDevices; } + const QDockWidget& dockDevices() const { Q_ASSERT(m_DockDevices); return *m_DockDevices; } + QDockWidget& dockOperations() { Q_ASSERT(m_DockOperations); return *m_DockOperations; } const QDockWidget& dockOperations() const { Q_ASSERT(m_DockOperations); return *m_DockOperations; } @@ -81,6 +87,8 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT MainWindow : public KXmlGuiWindow, publi const QLabel& statusText() const { Q_ASSERT(m_StatusText); return *m_StatusText; } protected slots: + void on_m_ListDevices_selectionChanged(Device* d); + void onDockLocationChanged(Qt::DockWidgetArea area); void closeEvent(QCloseEvent*); diff --git a/src/gui/mainwindowbase.ui b/src/gui/mainwindowbase.ui index 727815c..65ea233 100644 --- a/src/gui/mainwindowbase.ui +++ b/src/gui/mainwindowbase.ui @@ -20,6 +20,24 @@ + + + Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea + + + Devices + + + 1 + + + + + + + + + Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea @@ -75,6 +93,12 @@
gui/partitionmanagerwidget.h
1 + + ListDevices + QWidget +
gui/listdevices.h
+ 1 +
ListOperations QWidget diff --git a/src/kcm/partitionmanagerkcm.cpp b/src/kcm/partitionmanagerkcm.cpp index bb30da8..fea0c05 100644 --- a/src/kcm/partitionmanagerkcm.cpp +++ b/src/kcm/partitionmanagerkcm.cpp @@ -20,6 +20,7 @@ #include "kcm/partitionmanagerkcm.h" #include "gui/partitionmanagerwidget.h" +#include "gui/listdevices.h" #include "util/helpers.h" @@ -58,6 +59,7 @@ PartitionManagerKCM::PartitionManagerKCM(QWidget* parent, const QVariantList&) : setButtons(Apply); setupConnections(); + listDevices().init(actionCollection(), &pmWidget()); listOperations().init(actionCollection(), &pmWidget()); pmWidget().init(actionCollection(), "kcm_partitionmanagerrc"); @@ -102,7 +104,9 @@ void PartitionManagerKCM::onNewLogMessage(Log::Level, const QString& s) void PartitionManagerKCM::setupConnections() { + connect(&pmWidget(), SIGNAL(devicesChanged()), &listDevices(), SLOT(updateDevices())); connect(&pmWidget(), SIGNAL(operationsChanged()), &listOperations(), SLOT(updateOperations())); + connect(&listDevices(), SIGNAL(selectionChanged(Device*)), &pmWidget(), SLOT(setSelectedDevice(Device*))); connect(&pmWidget(), SIGNAL(statusChanged()), SLOT(onStatusChanged())); } diff --git a/src/kcm/partitionmanagerkcm.h b/src/kcm/partitionmanagerkcm.h index da90e16..815df66 100644 --- a/src/kcm/partitionmanagerkcm.h +++ b/src/kcm/partitionmanagerkcm.h @@ -29,6 +29,7 @@ #include class PartitionManagerWidget; +class ListDevices; class KActionCollection; class Device; class KToolBar; @@ -51,6 +52,7 @@ class PartitionManagerKCM : public KCModule, public Ui::PartitionManagerKCMBase void setupKCMWorkaround(); PartitionManagerWidget& pmWidget() { Q_ASSERT(m_PartitionManagerWidget); return *m_PartitionManagerWidget; } + ListDevices& listDevices() { Q_ASSERT(m_ListDevices); return *m_ListDevices; } ListOperations& listOperations() { Q_ASSERT(m_ListOperations); return *m_ListOperations; } QSplitter& splitterHorizontal() { Q_ASSERT(m_SplitterHorizontal); return *m_SplitterHorizontal; } QSplitter& splitterVertical() { Q_ASSERT(m_SplitterVertical); return *m_SplitterVertical; } diff --git a/src/kcm/partitionmanagerkcmbase.ui b/src/kcm/partitionmanagerkcmbase.ui index d60445b..98a457c 100644 --- a/src/kcm/partitionmanagerkcmbase.ui +++ b/src/kcm/partitionmanagerkcmbase.ui @@ -1,35 +1,43 @@ - - + PartitionManagerKCMBase - - + + 0 0 - 763 - 712 + 684 + 684 - + - - - Qt::Vertical + + + Qt::Horizontal - - - - Qt::Horizontal + + + Qt::Vertical - - + + - 200 + 170 0 - + + + + + + + + + + + @@ -42,6 +50,12 @@
gui/partitionmanagerwidget.h
1
+ + ListDevices + QWidget +
gui/listdevices.h
+ 1 +
ListOperations QWidget @@ -51,7 +65,7 @@ KToolBar QWidget -
ktoolbar.h
+
ktoolbar.h
1