1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#include <QPushButton>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
#include <QComboBox>
#include <QDirModel>
#include <QCompleter>
#include <QApplication>
#include <QSettings>
#include <QRegExp>
#include <QDebug>
#include "configurationdialog.h"
ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
//paths tab
QWidget *pathWidget = new QWidget;
QGridLayout *pathGrid = new QGridLayout;
mTab = new QTabWidget;
QDirModel *model = new QDirModel(this);
QCompleter *fsCompleter = new QCompleter(this);
fsCompleter->setModel(model);
fsCompleter->setCompletionMode(QCompleter::PopupCompletion);
QLabel *l1 = new QLabel(tr("Path to &picture viewer"));
mPictureViewer = new QLineEdit;
mPictureViewer->setCompleter(fsCompleter);
l1->setBuddy(mPictureViewer);
pathGrid->addWidget(l1, 0, 0);
pathGrid->addWidget(mPictureViewer, 0, 1);
QLabel *l2 = new QLabel(tr("Arguments for picture viewer"));
mPictureViewerArgs = new QLineEdit;
pathGrid->addWidget(l2, 1, 0);
pathGrid->addWidget(mPictureViewerArgs, 1, 1);
QLabel *l3 = new QLabel(tr("Path to &movie viewer"));
mMovieViewer = new QLineEdit;
mMovieViewer->setCompleter(fsCompleter);
l2->setBuddy(mMovieViewer);
pathGrid->addWidget(l3, 2, 0);
pathGrid->addWidget(mMovieViewer, 2, 1);
QLabel *l4 = new QLabel(tr("Arguments for movie viewer"));
mMovieViewerArgs = new QLineEdit;
pathGrid->addWidget(l4, 3, 0);
pathGrid->addWidget(mMovieViewerArgs, 3, 1);
QLabel *l5 = new QLabel(tr("Path to &archive program"));
mArchiver = new QLineEdit;
mArchiver->setCompleter(fsCompleter);
l5->setBuddy(mArchiver);
pathGrid->addWidget(l5, 4, 0);
pathGrid->addWidget(mArchiver, 4, 1);
QLabel *l6 = new QLabel(tr("Arguments for archive program"));
mArchiverArgs = new QLineEdit;
l6->setBuddy(mArchiverArgs);
pathGrid->addWidget(l6, 5, 0);
pathGrid->addWidget(mArchiverArgs, 5, 1);
QLabel *l7 = new QLabel(tr("Extraction paths"));
mArchivePaths = new QComboBox;
pathGrid->addWidget(l7, 6, 0);
pathGrid->addWidget(mArchivePaths);
QLabel *l8 = new QLabel(tr("Enter new &extraction path"));
mExtractPath = new QLineEdit;
mExtractPath->setCompleter(fsCompleter);
l8->setBuddy(mExtractPath);
pathGrid->addWidget(l8, 7, 0);
pathGrid->addWidget(mExtractPath, 7, 1);
mAddPath = new QPushButton(tr("Add path"));
connect(mAddPath, SIGNAL(clicked()), this, SLOT(addPath()));
mRemovePath = new QPushButton(tr("Remove path"));
connect(mRemovePath, SIGNAL(clicked()), this, SLOT(removePath()));
QHBoxLayout *pathButtonLayout = new QHBoxLayout;
pathButtonLayout->addStretch();
pathButtonLayout->addWidget(mAddPath);
pathButtonLayout->addWidget(mRemovePath);
pathGrid->addLayout(pathButtonLayout, 8, 1);
pathWidget->setLayout(pathGrid);
mTab->addTab(pathWidget, tr("Paths"));
//main layout
mOk = new QPushButton(tr("Ok"));
connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
mCancel = new QPushButton(tr("Cancel"));
connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout *mainButtonLayout = new QHBoxLayout;
mainButtonLayout->addStretch();
mainButtonLayout->addWidget(mOk);
mainButtonLayout->addWidget(mCancel);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mTab);
mainLayout->addLayout(mainButtonLayout);
setLayout(mainLayout);
QString winTitle = QString(tr("%1 - Configure")).arg(qApp->applicationName());
setWindowTitle(winTitle);
readSettings();
}
void ConfigurationDialog::accept(){
writeSettings();
QDialog::accept();
}
void ConfigurationDialog::addPath(){
QString newPath = mExtractPath->text();
if(!newPath.isEmpty() && !mPaths.contains(newPath)){
mArchivePaths->addItem(newPath);
mPaths.append(newPath);
}
}
void ConfigurationDialog::removePath(){
QString removePath = mArchivePaths->currentText();
int current = mArchivePaths->currentIndex();
if(!removePath.isEmpty()){
if(mPaths.contains(removePath)){
mPaths.removeOne(removePath);
mArchivePaths->removeItem(current);
}
}
}
void ConfigurationDialog::readSettings(){
QSettings s;
mPictureViewer->setText(s.value("paths/pictureviewer", "/usr/bin/gwenview").toString());
QStringList pvArgs = s.value("paths/pictureviewerargs").toStringList();
mPictureViewerArgs->setText(pvArgs.join(" "));
mMovieViewer->setText(s.value("paths/movieviewer", "/usr/bin/mplayer").toString());
QStringList mvArgs = s.value("paths/movieviewerargs").toStringList();
mMovieViewerArgs->setText(mvArgs.join(" "));
mArchiver->setText(s.value("paths/archiver", "/usr/bin/7z").toString());
QStringList arArgs = s.value("paths/archiverargs").toStringList();
mArchiverArgs->setText(arArgs.join(" "));
QStringList extractPaths = s.value("paths/extractpaths").toStringList();
mArchivePaths->addItems(extractPaths);
mPaths = extractPaths;
}
void ConfigurationDialog::writeSettings(){
QSettings s;
QRegExp splitAt("\\s+");
s.setValue("paths/pictureviewer", mPictureViewer->text());
QStringList pvArgs = mPictureViewerArgs->text().split(splitAt, QString::SkipEmptyParts);
s.setValue("paths/pictureviewerargs", pvArgs);
s.setValue("paths/movieviewer", mMovieViewer->text());
QStringList mvArgs = mMovieViewerArgs->text().split(splitAt, QString::SkipEmptyParts);
s.setValue("paths/movieviewerargs", mvArgs);
s.setValue("paths/archiver", mArchiver->text());
QStringList aArgs = mArchiverArgs->text().split(splitAt, QString::SkipEmptyParts);
s.setValue("paths/archiverargs", aArgs);
s.setValue("paths/extractpaths", mPaths);
}
|