00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "mainwindow.h"
00014 #include "listviewconfdir.h"
00015 #include "listviewitemconfigentry.h"
00016
00017
00018 #include <opie2/odebug.h>
00019 using namespace Opie::Core;
00020
00021
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qlineedit.h>
00025
00026 MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
00027 QMainWindow( parent, name, f ), _currentItem(0), _fileItem(0)
00028 {
00029 setCaption( tr("Conf File Editor") );
00030
00031
00032 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
00033
00034 mainLayout = new QVBoxLayout( this );
00035 mainLayout->setSpacing( 0 );
00036 mainLayout->setMargin( 0 );
00037
00038
00039 odebug << "creating settingList" << oendl;
00040 settingList = new ListViewConfDir( QDir::homeDirPath() + "/Settings", this, "settingslist");
00041 settingList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
00042 mainLayout->addWidget( settingList, 0);
00043
00044 odebug << "creating editor" << oendl;
00045 editor = new EditWidget(this);
00046 editor->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum));
00047 mainLayout->addWidget( editor, 1 );
00048 editor->layoutType( ListViewItemConf::File );
00049
00050 makeMenu();
00051
00052 connect(settingList, SIGNAL( pressed(QListViewItem*) ),
00053 this, SLOT(setCurrent(QListViewItem*)));
00054 connect( settingList, SIGNAL( clicked(QListViewItem*) ),
00055 this, SLOT( stopTimer(QListViewItem*) ) );
00056
00057 connect( editor->LineEditGroup, SIGNAL( textChanged(const QString&) ),
00058 SLOT( groupChanged(const QString&) ) );
00059 connect( editor->LineEditKey, SIGNAL( textChanged(const QString&) ),
00060 SLOT( keyChanged(const QString&) ) );
00061 connect( editor->LineEditValue, SIGNAL( textChanged(const QString&) ),
00062 SLOT( valueChanged(const QString&) ) );
00063
00064 setCurrent(0);
00065 editor->layoutType(EditWidget::File);
00066 }
00067
00068 void MainWindow::makeMenu()
00069 {
00070 popupTimer = new QTimer(this);
00071 popupMenuFile = new QPopupMenu(this);
00072 popupMenuEntry = new QPopupMenu(this);
00073
00074 popupActionSave = new QAction( tr("Save"),QString::null, 0, this, 0 );
00075 popupActionSave->addTo( popupMenuFile );
00076
00077 connect( popupActionSave, SIGNAL( activated() ),
00078 this , SLOT( saveConfFile() ) );
00079
00080 popupActionRevert = new QAction( tr("Revert"),QString::null, 0, this, 0 );
00081 popupActionRevert->addTo( popupMenuFile );
00082 popupActionRevert->addTo( popupMenuEntry );
00083 connect( popupActionRevert, SIGNAL( activated() ),
00084 this , SLOT( revertConfFile() ) );
00085
00086 popupActionDelete = new QAction( tr("Delete"),QString::null, 0, this, 0 );
00087 popupActionDelete->addTo( popupMenuFile );
00088 popupActionDelete->addTo( popupMenuEntry );
00089 connect( popupActionDelete, SIGNAL( activated() ),
00090 this , SLOT( removeConfFile() ) );
00091
00092 connect( popupTimer, SIGNAL(timeout()),
00093 this, SLOT(showPopup()) );
00094 }
00095
00096 MainWindow::~MainWindow()
00097 {
00098 }
00099
00100
00101
00102 void MainWindow::setCurrent(QListViewItem *item)
00103 {
00104
00105 if (!item) return;
00106 _item = (ListViewItemConf*) item;
00107 if (!_item) return;
00108 popupTimer->start( 750, true );
00109 if (_item->getType() == ListViewItemConf::File)
00110 {
00111 editor->layoutType(EditWidget::File);
00112 _currentItem=0;
00113 _fileItem = (ListViewItemConfFile*)item;
00114 return;
00115 }
00116 _fileItem = 0;
00117 _currentItem = (ListViewItemConfigEntry*)item;
00118 if (!_currentItem) return;
00119 QString file = _currentItem->getFile();
00120 QString group = _currentItem->getGroup();
00121 QString key = _currentItem->getKey();
00122 QString val = _currentItem->getValue();
00123 editor->TextFileName->setText(file);
00124 editor->LineEditGroup->setText(group);
00125 if (!key.isEmpty())
00126 {
00127 editor->layoutType(EditWidget::Entry);
00128 editor->LineEditKey->setText(key);
00129 editor->LineEditValue->setText(val);
00130 }else{
00131 editor->layoutType(EditWidget::Group);
00132 }
00133 }
00134
00135
00136 void MainWindow::groupChanged(const QString &g)
00137 {
00138 if (!_currentItem) return;
00139 _currentItem->setGroup(g);
00140 }
00141
00142 void MainWindow::keyChanged(const QString &k)
00143 {
00144 if (!_currentItem) return;
00145 _currentItem->keyChanged(k);
00146 }
00147
00148 void MainWindow::valueChanged(const QString &v)
00149 {
00150 if (!_currentItem) return;
00151 _currentItem->valueChanged(v);
00152 }
00153
00154
00155 void MainWindow::stopTimer( QListViewItem* )
00156 {
00157 popupTimer->stop();
00158 }
00159
00160 void MainWindow::saveConfFile()
00161 {
00162 if (!_fileItem) return;
00163 _fileItem->save();
00164 }
00165
00166 void MainWindow::revertConfFile()
00167 {
00168 if (!_item) return;
00169 _item->revert();
00170 }
00171
00172 void MainWindow::removeConfFile()
00173 {
00174 if (!_item) return;
00175 _item->remove();
00176 }
00177
00178 void MainWindow::showPopup()
00179 {
00180 odebug << "showPopup" << oendl;
00181 if (!_item) return;
00182 popupActionRevert->setEnabled(_item->revertable());
00183 popupActionSave->setEnabled(_item->isChanged());
00184 if (_fileItem)
00185 {
00186 popupActionSave->setEnabled(_fileItem->isChanged());
00187 popupMenuFile->popup( QCursor::pos() );
00188 }else if(_currentItem)
00189 {
00190 popupMenuEntry->popup( QCursor::pos() );
00191 }
00192 }