/
profilelistdialog.cpp
77 lines (67 loc) · 2.9 KB
/
profilelistdialog.cpp
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
#include "profilelistdialog.h"
#include "folderswindow.h"
ProfileListDialog::ProfileListDialog(QObject *parentw,XMLSettingsManager* manager) {
//Initialize objects.
profileList = new QListWidget();
addBtn = new QPushButton(QObject::trUtf8("Add"));
editBtn = new QPushButton(QObject::trUtf8("Edit"));
deleteBtn = new QPushButton(QObject::trUtf8("Delete"));
doneBtn = new QPushButton(QObject::trUtf8("Done"));
layout = new QGridLayout();
//Arrange layout
layout->addWidget(profileList,0,0,1,3);
layout->addWidget(addBtn,1,0,1,1);
layout->addWidget(editBtn,1,1,1,1);
layout->addWidget(deleteBtn,1,2,1,1);
layout->addWidget(doneBtn,2,0,1,3);
//Connect slots and signals
QObject::connect(doneBtn,SIGNAL(clicked()),this,SLOT(accept()));
QObject::connect(addBtn,SIGNAL(clicked()),this,SLOT(addProfile()));
QObject::connect(editBtn,SIGNAL(clicked()),this,SLOT(editProfile()));
QObject::connect(deleteBtn,SIGNAL(clicked()),this,SLOT(deleteProfile()));
QObject::connect(this,SIGNAL(accepted()),(FoldersWindow*)parentw,SLOT(refreshProfiles()));
xmlManager = manager;
refreshProfileList();
profileList->setCurrentRow(0);
this->setLayout(layout);
this->setWindowTitle(QObject::trUtf8("Manage Profiles"));
this->setModal(true);
this->resize(200,300);
}
void ProfileListDialog::addProfile() {
bool isOK;
QString name = QInputDialog::getText(this,QObject::trUtf8("Add Profile"),
QObject::trUtf8("Input the name of the new profile:"),
QLineEdit::Normal, "", &isOK);
if(isOK) {
xmlManager->addProfile(name);
}
refreshProfileList();
}
void ProfileListDialog::editProfile() {
bool isOK;
QString name = QInputDialog::getText(this,QObject::trUtf8("Edit Profile"),
QObject::trUtf8("Input a new name for the profile:"),
QLineEdit::Normal, "", &isOK);
if(isOK) {
xmlManager->editProfile(profileList->selectedItems().at(0)->text(),name);
}
refreshProfileList();
}
void ProfileListDialog::deleteProfile() {
QMessageBox message(QMessageBox::NoIcon,QObject::trUtf8("Delete Profile"),
QObject::trUtf8("Do you really want to delete this profile?"),
QMessageBox::Yes | QMessageBox::No , this);
if(message.exec() == QMessageBox::Yes) {
xmlManager->deleteProfile(profileList->selectedItems().at(0)->text());
}
refreshProfileList();
}
void ProfileListDialog::refreshProfileList() {
int oldRow = profileList->currentRow();
profileList->clear();
profileList->addItems(xmlManager->getProfiles());
profileList->setCurrentRow((profileList->count() <= oldRow ? profileList->count()-1 : oldRow));
deleteBtn->setEnabled(true);
if(profileList->count()==1) deleteBtn->setEnabled(false);
}