~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to parts/filter/shellinsertdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2002 by Bernd Gehrmann                                  *
 
3
 *   bernd@kdevelop.org                                                    *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 ***************************************************************************/
 
11
 
 
12
#include "shellinsertdlg.h"
 
13
 
 
14
#include <qcombobox.h>
 
15
#include <qlayout.h>
 
16
#include <qpushbutton.h>
 
17
#include <kconfig.h>
 
18
#include <kbuttonbox.h>
 
19
#include <kdebug.h>
 
20
#include <klocale.h>
 
21
#include <kmessagebox.h>
 
22
#include <kprocess.h>
 
23
#include <klineedit.h>
 
24
#include <kstdguiitem.h>
 
25
#include <kdeversion.h>
 
26
 
 
27
#include "kdevplugin.h"
 
28
#include "domutil.h"
 
29
#include "filterpart.h"
 
30
 
 
31
 
 
32
ShellInsertDialog::ShellInsertDialog()
 
33
    : QDialog(0, "shell filter dialog", true)
 
34
{
 
35
    QVBoxLayout *layout = new QVBoxLayout(this, 10, 4);
 
36
 
 
37
    combo = new QComboBox(true, this);
 
38
    combo->setDuplicatesEnabled(false);
 
39
    layout->addWidget(combo);
 
40
 
 
41
    KButtonBox *buttonbox = new KButtonBox(this);
 
42
    start_button = buttonbox->addButton(i18n("&Start"));
 
43
    start_button->setDefault(true);
 
44
#if KDE_IS_VERSION( 3, 2, 90 )
 
45
    cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
 
46
#else
 
47
    cancel_button = buttonbox->addButton(i18n("Cancel"));
 
48
#endif
 
49
    buttonbox->layout();
 
50
    layout->addWidget(buttonbox);
 
51
 
 
52
    connect( start_button, SIGNAL(clicked()),
 
53
             this, SLOT(slotStartClicked()) );
 
54
    connect( cancel_button, SIGNAL(clicked()),
 
55
             this, SLOT(reject()) );
 
56
    connect( combo->lineEdit(), SIGNAL(textChanged( const QString &)), this, SLOT(executeTextChanged( const QString &)));
 
57
    m_proc = 0;
 
58
 
 
59
    KConfig *config = FilterFactory::instance()->config();
 
60
    config->setGroup("General");
 
61
    QStringList items = config->readListEntry("InsertItems");
 
62
    combo->insertStringList(items);
 
63
    executeTextChanged( combo->lineEdit()->text());
 
64
 
 
65
}
 
66
 
 
67
 
 
68
ShellInsertDialog::~ShellInsertDialog()
 
69
{
 
70
    kdDebug(9029) << "~ShellInsertDialog" << endl;
 
71
    delete m_proc;
 
72
 
 
73
    // QComboBox API is a bit incomplete :-(
 
74
    QStringList list;
 
75
    for (int i=0; i < combo->count(); ++i)
 
76
        list << combo->text(i);
 
77
 
 
78
    KConfig *config = FilterFactory::instance()->config();
 
79
    config->setGroup("General");
 
80
    config->writeEntry("InsertItems", list);
 
81
}
 
82
 
 
83
 
 
84
void ShellInsertDialog::executeTextChanged( const QString &text)
 
85
{
 
86
    start_button->setEnabled(!text.isEmpty());
 
87
}
 
88
 
 
89
int ShellInsertDialog::exec()
 
90
{
 
91
    start_button->setEnabled(true);
 
92
    return QDialog::exec();
 
93
}
 
94
 
 
95
 
 
96
void ShellInsertDialog::slotStartClicked()
 
97
{
 
98
    start_button->setEnabled(false);
 
99
    m_str = QCString();
 
100
 
 
101
    delete m_proc;
 
102
    m_proc = new KShellProcess("/bin/sh");
 
103
    (*m_proc) << combo->currentText();
 
104
    connect( m_proc, SIGNAL(receivedStdout(KProcess*, char *, int)),
 
105
             this, SLOT(slotReceivedStdout(KProcess*, char *, int)) );
 
106
    connect( m_proc, SIGNAL(processExited(KProcess*)),
 
107
             this, SLOT(slotProcessExited(KProcess*)) );
 
108
    m_proc->start(KProcess::NotifyOnExit, KProcess::AllOutput);
 
109
}
 
110
 
 
111
 
 
112
void ShellInsertDialog::slotReceivedStdout(KProcess *, char *text, int len)
 
113
{
 
114
    m_str += QCString(text, len+1);
 
115
}
 
116
 
 
117
 
 
118
void ShellInsertDialog::slotProcessExited(KProcess *)
 
119
{
 
120
    if (m_proc->normalExit()) {
 
121
        accept();
 
122
    } else {
 
123
        KMessageBox::error(this, i18n("Process exited with status %1")
 
124
                           .arg(m_proc->exitStatus()));
 
125
        reject();
 
126
    }
 
127
}
 
128
 
 
129
#include "shellinsertdlg.moc"