~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to kross/modules/scriptmanageradd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 * scriptmanageradd.h
 
3
 * This file is part of the KDE project
 
4
 * copyright (C) 2006-2007 Sebastian Sauer <mail@dipe.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 * You should have received a copy of the GNU Library General Public License
 
15
 * along with this program; see the file COPYING.  If not, write to
 
16
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
 ***************************************************************************/
 
19
 
 
20
#include "scriptmanageradd.h"
 
21
#include "scriptmanagereditor.h"
 
22
#include "scriptmanager.h"
 
23
#include "formfile.h"
 
24
 
 
25
#include "../core/manager.h"
 
26
#include "../core/interpreter.h"
 
27
#include "../core/action.h"
 
28
#include "../core/actioncollection.h"
 
29
 
 
30
#include <QVBoxLayout>
 
31
#include <QHBoxLayout>
 
32
#include <QLabel>
 
33
//#include <QLineEdit>
 
34
//#include <QComboBox>
 
35
//#include <QCheckBox>
 
36
#include <QRadioButton>
 
37
//#include <kdeversion.h>
 
38
//#include <kconfig.h>
 
39
 
 
40
#include <klocale.h>
 
41
#include <kassistantdialog.h>
 
42
 
 
43
using namespace Kross;
 
44
 
 
45
/********************************************************************
 
46
 * ScriptManagerAddTypeWidget
 
47
 */
 
48
 
 
49
ScriptManagerAddTypeWidget::ScriptManagerAddTypeWidget(ScriptManagerAddWizard* wizard, QWidget* parent)
 
50
    : QWidget(parent), m_wizard(wizard)
 
51
{
 
52
    QVBoxLayout* layout = new QVBoxLayout(this);
 
53
    setLayout(layout);
 
54
    layout->addWidget( new QLabel(i18n("<qt>This wizard will guide you through the proccess of adding a new item to your scripts.</qt>"), this) );
 
55
    layout->addSpacing(10);
 
56
 
 
57
    m_scriptCheckbox = new QRadioButton(i18n("Add script file"), this);
 
58
    m_scriptCheckbox->setChecked(true);
 
59
    connect(m_scriptCheckbox, SIGNAL(toggled(bool)), this, SLOT(slotUpdate()));
 
60
    layout->addWidget(m_scriptCheckbox);
 
61
 
 
62
    m_collectionCheckbox = new QRadioButton(i18n("Add collection folder"), this);
 
63
    layout->addWidget(m_collectionCheckbox);
 
64
 
 
65
    m_installCheckBox = new QRadioButton(i18n("Install script package file"), this);
 
66
    m_installCheckBox->setEnabled(false);
 
67
    layout->addWidget(m_installCheckBox);
 
68
 
 
69
    m_onlineCheckbox = new QRadioButton(i18n("Install online script package"), this);
 
70
    m_onlineCheckbox->setEnabled(false);
 
71
    layout->addWidget(m_onlineCheckbox);
 
72
 
 
73
    layout->addStretch(1);
 
74
}
 
75
 
 
76
void ScriptManagerAddTypeWidget::slotUpdate()
 
77
{
 
78
    m_wizard->m_dialog->setAppropriate(m_wizard->m_fileItem, m_scriptCheckbox->isChecked());
 
79
    m_wizard->m_dialog->setAppropriate(m_wizard->m_scriptItem, m_scriptCheckbox->isChecked());
 
80
    m_wizard->m_dialog->setAppropriate(m_wizard->m_collectionItem, m_collectionCheckbox->isChecked());
 
81
    //m_installCheckBox->isChecked()
 
82
    //m_onlineCheckbox->isChecked()
 
83
}
 
84
 
 
85
/********************************************************************
 
86
 * ScriptManagerAddFileWidget
 
87
 */
 
88
 
 
89
ScriptManagerAddFileWidget::ScriptManagerAddFileWidget(ScriptManagerAddWizard* wizard, QWidget* parent, const QString& startDirOrVariable)
 
90
    : QWidget(parent), m_wizard(wizard)
 
91
{
 
92
    QVBoxLayout* layout = new QVBoxLayout(this);
 
93
    layout->setMargin(0);
 
94
    setLayout(layout);
 
95
    m_filewidget = new FormFileWidget(this, startDirOrVariable);
 
96
 
 
97
    QStringList mimetypes;
 
98
    foreach(QString interpretername, Manager::self().interpreters()) {
 
99
        InterpreterInfo* info = Manager::self().interpreterInfo(interpretername);
 
100
        Q_ASSERT( info );
 
101
        mimetypes.append( info->mimeTypes().join(" ").trimmed() );
 
102
    }
 
103
    m_filewidget->setMimeFilter(mimetypes /*, defaultmime*/);
 
104
 
 
105
    layout->addWidget( m_filewidget );
 
106
    connect(m_filewidget, SIGNAL(fileHighlighted(const QString&)), this, SLOT(slotUpdate()));
 
107
    connect(m_filewidget, SIGNAL(fileSelected(const QString&)), this, SLOT(slotUpdate()));
 
108
}
 
109
 
 
110
void ScriptManagerAddFileWidget::slotUpdate()
 
111
{
 
112
    m_wizard->m_dialog->setValid(m_wizard->m_fileItem, ! m_filewidget->selectedFile().isEmpty());
 
113
}
 
114
 
 
115
/********************************************************************
 
116
 * ScriptManagerAddScriptWidget
 
117
 */
 
118
 
 
119
ScriptManagerAddScriptWidget::ScriptManagerAddScriptWidget(ScriptManagerAddWizard* wizard, QWidget* parent)
 
120
    : QWidget(parent), m_wizard(wizard)
 
121
{
 
122
    QVBoxLayout* layout = new QVBoxLayout(this);
 
123
    setLayout(layout);
 
124
    Action* action = new Action(0, "");
 
125
    m_editor = new ScriptManagerEditor(action, this);
 
126
    layout->addWidget(m_editor);
 
127
}
 
128
 
 
129
void ScriptManagerAddScriptWidget::slotUpdate()
 
130
{
 
131
    m_wizard->m_dialog->setValid(m_wizard->m_scriptItem, m_editor->isValid());
 
132
}
 
133
 
 
134
/********************************************************************
 
135
 * ScriptManagerAddCollectionWidget
 
136
 */
 
137
 
 
138
ScriptManagerAddCollectionWidget::ScriptManagerAddCollectionWidget(ScriptManagerAddWizard* wizard, QWidget* parent)
 
139
    : QWidget(parent), m_wizard(wizard)
 
140
{
 
141
    QVBoxLayout* layout = new QVBoxLayout(this);
 
142
    setLayout(layout);
 
143
    ActionCollection* collection = new ActionCollection("");
 
144
    m_editor = new ScriptManagerEditor(collection, this);
 
145
    layout->addWidget(m_editor);
 
146
}
 
147
 
 
148
void ScriptManagerAddCollectionWidget::slotUpdate()
 
149
{
 
150
    m_wizard->m_dialog->setValid(m_wizard->m_collectionItem, m_editor->isValid());
 
151
}
 
152
 
 
153
/********************************************************************
 
154
 * ScriptManagerAddWizard
 
155
 */
 
156
 
 
157
ScriptManagerAddWizard::ScriptManagerAddWizard(QWidget* parent)
 
158
    : QObject()
 
159
{
 
160
    m_dialog = new KAssistantDialog(parent);
 
161
    m_dialog->setCaption( i18n("Add") );
 
162
 
 
163
    ScriptManagerAddTypeWidget* typewidget = new ScriptManagerAddTypeWidget(this, m_dialog);
 
164
    m_typeItem = m_dialog->addPage(typewidget, i18n("Add"));
 
165
 
 
166
    const QString startDirOrVariable = "kfiledialog:///scriptmanageraddfile";
 
167
    ScriptManagerAddFileWidget* filewidget = new ScriptManagerAddFileWidget(this, m_dialog, startDirOrVariable);
 
168
    m_fileItem = m_dialog->addPage(filewidget, i18n("Script File"));
 
169
 
 
170
    ScriptManagerAddScriptWidget* scriptwidget = new ScriptManagerAddScriptWidget(this, m_dialog);
 
171
    m_scriptItem = m_dialog->addPage(scriptwidget, i18n("Script"));
 
172
 
 
173
    ScriptManagerAddCollectionWidget* collectionwidget = new ScriptManagerAddCollectionWidget(this, m_dialog);
 
174
    m_collectionItem = m_dialog->addPage(collectionwidget, i18n("Collection"));
 
175
 
 
176
    m_dialog->resize( QSize(620, 460).expandedTo( m_dialog->minimumSizeHint() ) );
 
177
 
 
178
    //connect(m_dialog, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(slotUpdate()));
 
179
    typewidget->slotUpdate();
 
180
    filewidget->slotUpdate();
 
181
    scriptwidget->slotUpdate();
 
182
    collectionwidget->slotUpdate();
 
183
}
 
184
 
 
185
ScriptManagerAddWizard::~ScriptManagerAddWizard()
 
186
{
 
187
    delete m_dialog;
 
188
    m_dialog = 0;
 
189
}
 
190
 
 
191
int ScriptManagerAddWizard::execWizard()
 
192
{
 
193
    return m_dialog->exec();
 
194
}
 
195
 
 
196
#include "scriptmanageradd.moc"