Clean up the code a little.
Work around the problem that we're in our own KDialog if we're root with our own Ok-button that will kill our OperationRunner thread if clicked. svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=958262
This commit is contained in:
parent
59c7dcb9f7
commit
8a9c925636
|
@ -30,6 +30,7 @@
|
|||
#include <klocale.h>
|
||||
#include <kactioncollection.h>
|
||||
#include <ktoolbar.h>
|
||||
#include <kapplication.h>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
|
@ -55,7 +56,6 @@ PartitionManagerKCM::PartitionManagerKCM(QWidget* parent, const QVariantList&) :
|
|||
registerMetaTypes();
|
||||
|
||||
setButtons(Apply);
|
||||
|
||||
setupConnections();
|
||||
|
||||
listDevices().init(actionCollection(), &pmWidget());
|
||||
|
@ -78,19 +78,21 @@ PartitionManagerKCM::PartitionManagerKCM(QWidget* parent, const QVariantList&) :
|
|||
"refreshDevices"
|
||||
};
|
||||
|
||||
for(size_t i = 0; i < sizeof(actionNames) / sizeof(actionNames[0]); i++)
|
||||
for (size_t i = 0; i < sizeof(actionNames) / sizeof(actionNames[0]); i++)
|
||||
if (strlen(actionNames[i]) > 0)
|
||||
toolBar()->addAction(actionCollection()->action(actionNames[i]));
|
||||
toolBar().addAction(actionCollection()->action(actionNames[i]));
|
||||
else
|
||||
toolBar()->addSeparator();
|
||||
toolBar().addSeparator();
|
||||
|
||||
toolBar()->setIconSize(QSize(22, 22));
|
||||
toolBar()->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
toolBar().setIconSize(QSize(22, 22));
|
||||
toolBar().setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
|
||||
splitterHorizontal().setStretchFactor(0, 1);
|
||||
splitterHorizontal().setStretchFactor(1, 4);
|
||||
splitterVertical().setStretchFactor(0, 1);
|
||||
splitterVertical().setStretchFactor(1, 3);
|
||||
|
||||
setupKCMWorkaround();
|
||||
}
|
||||
|
||||
void PartitionManagerKCM::onNewLogMessage(log::Level, const QString& s)
|
||||
|
@ -98,22 +100,6 @@ void PartitionManagerKCM::onNewLogMessage(log::Level, const QString& s)
|
|||
kDebug() << s;
|
||||
}
|
||||
|
||||
void PartitionManagerKCM::load()
|
||||
{
|
||||
if (pmWidget().numPendingOperations() > 0)
|
||||
actionCollection()->action("clearAllOperations")->trigger();
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(onStatusChanged()));
|
||||
}
|
||||
|
||||
void PartitionManagerKCM::save()
|
||||
{
|
||||
if (pmWidget().numPendingOperations() > 0)
|
||||
actionCollection()->action("applyAllOperations")->trigger();
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(onStatusChanged()));
|
||||
}
|
||||
|
||||
void PartitionManagerKCM::setupConnections()
|
||||
{
|
||||
connect(&pmWidget(), SIGNAL(devicesChanged()), &listDevices(), SLOT(updateDevices()));
|
||||
|
@ -126,3 +112,37 @@ void PartitionManagerKCM::onStatusChanged()
|
|||
{
|
||||
emit changed(pmWidget().numPendingOperations() > 0);
|
||||
}
|
||||
|
||||
void PartitionManagerKCM::setupKCMWorkaround()
|
||||
{
|
||||
// The Partition Manager kcm must be run as root, for obvious reasons. system-settings will
|
||||
// open kcms that require root privileges in a separate kcmshell4 process with a window of
|
||||
// its own. This window (a KDialog, actually) has a couple of buttons at the bottom, one of
|
||||
// them an Ok-button. The user will expect to have his changes applied if he clicks that button.
|
||||
// Unfortunately, we cannot do that: The kcmshell will kill us and our OperationRunner thread
|
||||
// without asking us as soon as we return from PartitionManagerKCM::save(). Even worse, we
|
||||
// have no way to find out if PartitionMangerKCM::save() was called because the user clicked
|
||||
// on "Ok" or "Apply" -- if we had that way we could at least do nothing in the case of the
|
||||
// Ok button...
|
||||
// Anyway, there seems to be no other solution than find the KDialog and turn off all buttons we
|
||||
// cannot handle... Nasty, but effective for now.
|
||||
foreach(QWidget* w, KApplication::topLevelWidgets())
|
||||
{
|
||||
KDialog* dlg = qobject_cast<KDialog*>(w);
|
||||
if (dlg != NULL)
|
||||
{
|
||||
dlg->setButtons(KDialog::Cancel|KDialog::Apply);
|
||||
dlg->enableButtonApply(false);
|
||||
connect(dlg, SIGNAL(applyClicked()), SLOT(onApplyClicked()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PartitionManagerKCM::onApplyClicked()
|
||||
{
|
||||
if (pmWidget().numPendingOperations() > 0)
|
||||
actionCollection()->action("applyAllOperations")->trigger();
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(onStatusChanged()));
|
||||
}
|
||||
|
||||
|
|
|
@ -43,31 +43,26 @@ class PartitionManagerKCM : public KCModule, public Ui::PartitionManagerKCMBase
|
|||
virtual ~PartitionManagerKCM() {}
|
||||
|
||||
public:
|
||||
void load();
|
||||
void save();
|
||||
void load() {}
|
||||
void save() {}
|
||||
|
||||
protected:
|
||||
void setupConnections();
|
||||
void setupKCMWorkaround();
|
||||
|
||||
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; }
|
||||
|
||||
QSplitter& splitterHorizontal() { Q_ASSERT(m_SplitterHorizontal); return *m_SplitterHorizontal; }
|
||||
QSplitter& splitterVertical() { Q_ASSERT(m_SplitterVertical); return *m_SplitterVertical; }
|
||||
KToolBar& toolBar() { Q_ASSERT(m_ToolBar); return *m_ToolBar; }
|
||||
|
||||
KActionCollection* actionCollection() { return m_ActionCollection; }
|
||||
|
||||
KToolBar* toolBar() { return m_ToolBar; }
|
||||
|
||||
protected slots:
|
||||
void onNewLogMessage(log::Level logLevel, const QString& s);
|
||||
void onStatusChanged();
|
||||
void onApplyClicked();
|
||||
|
||||
private:
|
||||
KActionCollection* m_ActionCollection;
|
||||
|
@ -75,4 +70,3 @@ class PartitionManagerKCM : public KCModule, public Ui::PartitionManagerKCMBase
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue