KEditToolBar ported to KProcess
Andreas Pakulat
apaku at gmx.de
Tue Jun 12 18:17:26 BST 2007
Hi,
before I commit this I'd like to have some review that I didn't do
anything wrong. I'm not sure how to test this class as there doesn't
seem to exist a test.
If nobody objects I'll commit this in 2 or 3 days (its BC afaik) and
then start to work through the lxr output for K3Process/K3ProcIO in
kdelibs in a similar way.
Andreas
--
Ships are safe in harbor, but they were never meant to stay there.
-------------- next part --------------
Index: kedittoolbar.cpp
===================================================================
--- kedittoolbar.cpp (Revision 674577)
+++ kedittoolbar.cpp (Arbeitskopie)
@@ -29,6 +29,7 @@
#include <QtGui/QLabel>
#include <QtGui/QApplication>
#include <QtCore/QTextIStream>
+#include <QtCore/QProcess>
#include <QTreeWidget>
#include <QMimeData>
@@ -44,7 +45,7 @@
#include <kconfig.h>
#include <kdebug.h>
#include <kpushbutton.h>
-#include <k3procio.h>
+#include <kprocess.h>
#include <ktoolbar.h>
#include "kaction.h"
@@ -176,7 +177,7 @@
* In a KParts application we let create a KXMLGUIClient create a dummy one,
* but it probably isn't used.
*/
- KEditToolBarWidgetPrivate(KEditToolBarWidget* widget,
+ KEditToolBarWidgetPrivate(KEditToolBarWidget* widget,
const KComponentData &cData, KActionCollection* collection)
: m_collection( collection ),
m_widget (widget),
@@ -193,29 +194,29 @@
// private slots
void slotToolBarSelected(const QString& text);
-
+
void slotInactiveSelectionChanged();
void slotActiveSelectionChanged();
-
+
void slotInsertButton();
void slotRemoveButton();
void slotUpButton();
void slotDownButton();
-
+
void slotChangeIcon();
-
- void slotProcessExited( K3Process* );
-
+ void slotProcessExited();
+
+
void setupLayout();
-
+
void initNonKPart( const QString& file, bool global, const QString& defaultToolbar );
void initKPart( KXMLGUIFactory* factory, const QString& defaultToolbar );
void loadToolBarCombo( const QString& defaultToolbar );
void loadActionList(QDomElement& elem);
-
+
QString xmlFile(const QString& xml_file)
{
return xml_file.isNull() ? QString(m_componentData.componentName()) + "ui.rc" :
@@ -332,12 +333,12 @@
#endif
QComboBox *m_toolbarCombo;
-
+
QToolButton *m_upAction;
QToolButton *m_removeAction;
QToolButton *m_insertAction;
QToolButton *m_downAction;
-
+
//QValueList<KAction*> m_actionList;
KActionCollection* m_collection;
KEditToolBarWidget* m_widget;
@@ -362,7 +363,7 @@
KSeparator *m_comboSeparator;
QLabel * m_helpArea;
KPushButton* m_changeIcon;
- K3ProcIO* m_kdialogProcess;
+ KProcess* m_kdialogProcess;
bool m_hasKDialog;
bool m_loadedOnce;
};
@@ -1344,10 +1345,10 @@
//if the process is already running (e.g. when somebody clicked the change button twice (see #127149)) - do nothing...
//otherwise m_kdialogProcess will be overwritten and set to zero in slotProcessExited()...crash!
- if ( m_kdialogProcess && m_kdialogProcess->isRunning() )
+ if ( m_kdialogProcess && m_kdialogProcess->state() == QProcess::Running )
return;
- m_kdialogProcess = new K3ProcIO;
+ m_kdialogProcess = new KProcess;
QString kdialogExe = KStandardDirs::findExe(QLatin1String("kdialog"));
(*m_kdialogProcess) << kdialogExe;
(*m_kdialogProcess) << "--embed";
@@ -1355,7 +1356,10 @@
(*m_kdialogProcess) << "--geticon";
(*m_kdialogProcess) << "Toolbar";
(*m_kdialogProcess) << "Actions";
- if ( !m_kdialogProcess->start( K3Process::NotifyOnExit ) ) {
+ m_kdialogProcess->setOutputChannelMode(KProcess::MergedChannels);
+ m_kdialogProcess->setNextOpenMode( QIODevice::ReadOnly | QIODevice::Text );
+ m_kdialogProcess->start();
+ if ( !m_kdialogProcess->waitForStarted() ) {
kError(240) << "Can't run " << kdialogExe << endl;
delete m_kdialogProcess;
m_kdialogProcess = 0;
@@ -1365,11 +1369,11 @@
m_activeList->setEnabled( false ); // don't change the current item
m_toolbarCombo->setEnabled( false ); // don't change the current toolbar
- QObject::connect( m_kdialogProcess, SIGNAL( processExited( K3Process* ) ),
- m_widget, SLOT( slotProcessExited( K3Process* ) ) );
+ QObject::connect( m_kdialogProcess, SIGNAL( processExited( int, QProcess::ExitStatus ) ),
+ m_widget, SLOT( slotProcessExited() ) );
}
-void KEditToolBarWidgetPrivate::slotProcessExited( K3Process* )
+void KEditToolBarWidgetPrivate::slotProcessExited()
{
m_activeList->setEnabled( true );
m_toolbarCombo->setEnabled( true );
@@ -1381,9 +1385,10 @@
return;
}
- if ( !m_kdialogProcess->normalExit() ||
- m_kdialogProcess->exitStatus() ||
- m_kdialogProcess->readln(icon, true) <= 0 ) {
+ icon = QString::fromLocal8Bit( m_kdialogProcess->readAllStandardOutput() );
+ icon = icon.left( icon.indexOf( "\n" ) );
+ if ( m_kdialogProcess->exitStatus() != QProcess::NormalExit ||
+ icon.length() == 0 ) {
delete m_kdialogProcess;
m_kdialogProcess = 0;
return;
Index: kedittoolbar.h
===================================================================
--- kedittoolbar.h (Revision 674577)
+++ kedittoolbar.h (Arbeitskopie)
@@ -23,7 +23,7 @@
#include <kxmlguiclient.h>
#include <kdialog.h>
-class K3Process;
+class KProcess;
class KActionCollection;
class QTreeWidget;
@@ -363,12 +363,12 @@
Q_PRIVATE_SLOT(d, void slotChangeIcon())
- Q_PRIVATE_SLOT(d, void slotProcessExited( K3Process* ))
+ Q_PRIVATE_SLOT(d, void slotProcessExited())
private:
friend class KEditToolBarWidgetPrivate;
KEditToolBarWidgetPrivate *const d;
-
+
Q_DISABLE_COPY(KEditToolBarWidget)
};
More information about the kde-core-devel
mailing list