summaryrefslogtreecommitdiff
path: root/noncore/apps/confedit/mainwindow.cpp
Unidiff
Diffstat (limited to 'noncore/apps/confedit/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/confedit/mainwindow.cpp195
1 files changed, 195 insertions, 0 deletions
diff --git a/noncore/apps/confedit/mainwindow.cpp b/noncore/apps/confedit/mainwindow.cpp
new file mode 100644
index 0000000..5eeeb90
--- a/dev/null
+++ b/noncore/apps/confedit/mainwindow.cpp
@@ -0,0 +1,195 @@
1/***************************************************************************
2 * *
3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. *
7 * *
8 ***************************************************************************/
9
10// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
11
12
13#include "mainwindow.h"
14
15#include <qpe/qpemenubar.h>
16#include <qpe/qpemessagebox.h>
17#include <qpe/resource.h>
18#include <qpe/config.h>
19#include <qpe/qpetoolbar.h>
20#include <qaction.h>
21#include <qmessagebox.h>
22#include <qpopupmenu.h>
23#include <qtoolbutton.h>
24#include <qstring.h>
25#include <qlabel.h>
26#include <qfile.h>
27#include <qpushbutton.h>
28#include <qlayout.h>
29#include <qlineedit.h>
30
31#include "listviewconfdir.h"
32#include "listviewitemconf.h"
33#include "listviewitemconfigentry.h"
34
35
36MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
37 QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0)
38 {
39 setCaption( tr("Conf File Editor") );
40
41 popupTimer = new QTimer(this);
42 popupMenu = new QPopupMenu(this);
43
44 QWidget *mainWidget = new QWidget(this);
45 setCentralWidget( mainWidget);
46
47 QGridLayout *mainLayout = new QGridLayout( mainWidget );
48 mainLayout->setSpacing( 3 );
49 mainLayout->setMargin( 3 );
50
51
52 settingList = new ListViewConfDir( "/root/Settings/", this, "settingslist");
53 mainLayout->addWidget( settingList, 0, 0 );
54
55 editor = new EditWidget(this);
56 mainLayout->addWidget( editor, 1, 0 );
57
58 connect (settingList, SIGNAL( currentChanged(QListViewItem*) ),
59 this, SLOT(setCurrent(QListViewItem*)));
60
61 connect( popupTimer, SIGNAL(timeout()),
62 this, SLOT(showPopup()) );
63 connect( this, SIGNAL( clicked( QListViewItem* ) ),
64 this, SLOT( stopTimer( QListViewItem* ) ) );
65
66 connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ),
67 SLOT( groupChanged(const QString&) ) );
68 connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ),
69 SLOT( keyChanged(const QString&) ) );
70 connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ),
71 SLOT( valueChanged(const QString&) ) );
72 makeMenu();
73}
74
75void MainWindow::makeMenu()
76{
77
78
79}
80
81MainWindow::~MainWindow()
82{
83}
84
85
86
87void MainWindow::setCurrent(QListViewItem *item)
88{
89 qDebug("MainWindow::setCurrent(");
90 if (!item) return;
91 qDebug("cast ListViewItemConf");
92 ListViewItemConf *i = (ListViewItemConf*) item;
93 if (!i) return;
94 if (i->getType() == ListViewItemConf::File)
95 {
96 popupTimer->start( 750, true );
97 editor->hide();
98 updateGeometry();
99 _currentItem=0;
100 _fileItem = (ListViewItemConfFile*)item;
101 return;
102 }else editor->show();
103 qDebug("cast ListViewItemConfigEntry");
104 _fileItem = 0;
105 _currentItem = (ListViewItemConfigEntry*)item;
106 if (!_currentItem) return;
107 QString file = _currentItem->getFile();
108 QString group = _currentItem->getGroup();
109 QString key = _currentItem->getKey();
110 QString val = _currentItem->getValue();
111 editor->TextFileName->setText(file);
112 editor->LineEditGroup->setText(group);
113 if (!key.isEmpty())
114 {
115 editor->isKey(true);
116 editor->LineEditKey->setText(key);
117 editor->LineEditValue->setText(val);
118 }else{
119 editor->isKey(false);
120 }
121 updateGeometry();
122}
123
124
125void MainWindow::groupChanged(const QString &g)
126{
127 if (!_currentItem) return;
128 _currentItem->setGroup(g);
129}
130
131void MainWindow::keyChanged(const QString &k)
132{
133 if (!_currentItem) return;
134 _currentItem->keyChanged(k);
135}
136
137void MainWindow::valueChanged(const QString &v)
138{
139 if (!_currentItem) return;
140 _currentItem->valueChanged(v);
141}
142
143
144void MainWindow::stopTimer( QListViewItem* )
145{
146 qDebug("stopTimer");
147 popupTimer->stop();
148}
149
150void MainWindow::saveConfFile()
151{
152 if (!_fileItem) return;
153 _fileItem->save();
154}
155
156void MainWindow::showPopup()
157{
158 qDebug("showPopup");
159 if (!_fileItem) return;
160 popupMenu->clear();
161
162 QAction *popupAction;
163 popupAction = new QAction( tr("Save"),QString::null, 0, this, 0 );
164 popupAction->addTo( popupMenu );
165 connect( popupAction, SIGNAL( activated() ),
166 this , SLOT( saveConfFile() ) );
167
168// if ( !activePackage->installed() )
169// {
170 // popupMenu->insertItem( tr("Install to"), destsMenu );
171 // QStringList dests = settings->getDestinationNames();
172 // QString ad = settings->getDestinationName();
173 // for (uint i = 0; i < dests.count(); i++ )
174 // {
175 // popupAction = new QAction( dests[i], QString::null, 0, this, 0 );
176 // popupAction->addTo( destsMenu );
177 // if ( dests[i] == ad && activePackage->toInstall() )
178 // {
179// popupAction->setToggleAction( true );
180 // popupAction->setOn(true);
181 // };
182 // }
183 // connect( destsMenu, SIGNAL( activated( int ) ),
184 // this, SLOT( changePackageDest( int ) ) );
185// }else{
186 // popupAction = new QAction( tr("Remove"),QString::null, 0, this, 0 );
187 // popupAction->addTo( popupMenu );
188 // connect( popupAction, SIGNAL( activated() ),
189 // this , SLOT( toggleProcess() ) );
190 // popupAction = new QAction( tr("Reinstall"),QString::null, 0, this, 0 );
191 // popupAction->addTo( popupMenu );
192 // popupAction->setEnabled( false );
193// }
194 popupMenu->popup( QCursor::pos() );
195}