KDevelop API Documentation

shellinsertdlg.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2002 by Bernd Gehrmann                                  *
00003  *   bernd@kdevelop.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include "shellinsertdlg.h"
00013 
00014 #include <qcombobox.h>
00015 #include <qlayout.h>
00016 #include <qpushbutton.h>
00017 #include <kconfig.h>
00018 #include <kbuttonbox.h>
00019 #include <kdebug.h>
00020 #include <klocale.h>
00021 #include <kmessagebox.h>
00022 #include <kprocess.h>
00023 #include <klineedit.h>
00024 #include <kstdguiitem.h>
00025 #include <kdeversion.h>
00026 
00027 #include "kdevplugin.h"
00028 #include "domutil.h"
00029 #include "filterpart.h"
00030 
00031 
00032 ShellInsertDialog::ShellInsertDialog()
00033     : QDialog(0, "shell filter dialog", true)
00034 {
00035     QVBoxLayout *layout = new QVBoxLayout(this, 10, 4);
00036 
00037     combo = new QComboBox(true, this);
00038     combo->setDuplicatesEnabled(false);
00039     layout->addWidget(combo);
00040 
00041     KButtonBox *buttonbox = new KButtonBox(this);
00042     start_button = buttonbox->addButton(i18n("&Start"));
00043     start_button->setDefault(true);
00044 #if KDE_IS_VERSION( 3, 2, 90 )
00045     cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
00046 #else
00047     cancel_button = buttonbox->addButton(i18n("Cancel"));
00048 #endif
00049     buttonbox->layout();
00050     layout->addWidget(buttonbox);
00051 
00052     connect( start_button, SIGNAL(clicked()),
00053              this, SLOT(slotStartClicked()) );
00054     connect( cancel_button, SIGNAL(clicked()),
00055              this, SLOT(reject()) );
00056     connect( combo->lineEdit(), SIGNAL(textChanged( const QString &)), this, SLOT(executeTextChanged( const QString &)));
00057     m_proc = 0;
00058 
00059     KConfig *config = FilterFactory::instance()->config();
00060     config->setGroup("General");
00061     QStringList items = config->readListEntry("InsertItems");
00062     combo->insertStringList(items);
00063     executeTextChanged( combo->lineEdit()->text());
00064 
00065 }
00066 
00067 
00068 ShellInsertDialog::~ShellInsertDialog()
00069 {
00070     kdDebug(9029) << "~ShellInsertDialog" << endl;
00071     delete m_proc;
00072 
00073     // QComboBox API is a bit incomplete :-(
00074     QStringList list;
00075     for (int i=0; i < combo->count(); ++i)
00076         list << combo->text(i);
00077 
00078     KConfig *config = FilterFactory::instance()->config();
00079     config->setGroup("General");
00080     config->writeEntry("InsertItems", list);
00081 }
00082 
00083 
00084 void ShellInsertDialog::executeTextChanged( const QString &text)
00085 {
00086     start_button->setEnabled(!text.isEmpty());
00087 }
00088 
00089 int ShellInsertDialog::exec()
00090 {
00091     start_button->setEnabled(true);
00092     return QDialog::exec();
00093 }
00094 
00095 
00096 void ShellInsertDialog::slotStartClicked()
00097 {
00098     start_button->setEnabled(false);
00099     m_str = QCString();
00100 
00101     delete m_proc;
00102     m_proc = new KShellProcess("/bin/sh");
00103     (*m_proc) << combo->currentText();
00104     connect( m_proc, SIGNAL(receivedStdout(KProcess*, char *, int)),
00105              this, SLOT(slotReceivedStdout(KProcess*, char *, int)) );
00106     connect( m_proc, SIGNAL(processExited(KProcess*)),
00107              this, SLOT(slotProcessExited(KProcess*)) );
00108     m_proc->start(KProcess::NotifyOnExit, KProcess::AllOutput);
00109 }
00110 
00111 
00112 void ShellInsertDialog::slotReceivedStdout(KProcess *, char *text, int len)
00113 {
00114     m_str += QCString(text, len+1);
00115 }
00116 
00117 
00118 void ShellInsertDialog::slotProcessExited(KProcess *)
00119 {
00120     if (m_proc->normalExit()) {
00121         accept();
00122     } else {
00123         KMessageBox::error(this, i18n("Process exited with status %1")
00124                            .arg(m_proc->exitStatus()));
00125         reject();
00126     }
00127 }
00128 
00129 #include "shellinsertdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003