-
Notifications
You must be signed in to change notification settings - Fork 42
/
ZDLIWadList.cpp
129 lines (112 loc) · 3.46 KB
/
ZDLIWadList.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
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
/*
* This file is part of qZDL
* Copyright (C) 2007-2010 Cody Harris
*
* qZDL 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ZDLIWadList.h"
#include "ZDLNameListable.h"
#include "zdlconf.h"
#include "ZDLNameInput.h"
ZDLIWadList::ZDLIWadList(ZDLWidget *parent): ZDLListWidget(parent){
}
void ZDLIWadList::newConfig(){
pList->clear();
auto zconf = ZDLConfigurationManager::getActiveConfiguration();
for (int i = 0; ; i++)
{
auto nameKey = QString("zdl.iwads/i%1n").arg(i);
auto fileKey = QString("zdl.iwads/i%1f").arg(i);
if (!zconf->contains(nameKey) || !zconf->contains(fileKey))
{
break;
}
auto fileName = zconf->value(fileKey).toString();
auto disName = zconf->value(nameKey).toString();
ZDLNameListable *zList = new ZDLNameListable(pList, 1001, fileName, disName);
insert(zList, -1);
}
}
void ZDLIWadList::rebuild(){
auto zconf = ZDLConfigurationManager::getActiveConfiguration();
zconf->beginGroup("zdl.iwads");
zconf->remove("");
for(int i = 0; i < count(); i++){
QListWidgetItem *itm = pList->item(i);
ZDLNameListable* fitm = (ZDLNameListable*)itm;
zconf->setValue(QString("i%1n").arg(i), fitm->getName());
zconf->setValue(QString("i%1f").arg(i), fitm->getFile());
}
zconf->endGroup();
}
void ZDLIWadList::newDrop(QStringList fileList){
for(int i = 0; i < fileList.size(); i++){
ZDLNameListable *zList = NULL;
QString entry = fileList[i];
QStringList pathParts = entry.split("/");
if(pathParts.size() > 1){
QString file = pathParts.last();
QStringList fileParts = file.split(".");
if(fileParts.size() > 1){
QString name = fileParts[0];
zList = new ZDLNameListable(pList, 1001, entry, name);
}else{
zList = new ZDLNameListable(pList, 1001, entry, file);
}
}else{
zList = new ZDLNameListable(pList, 1001, entry, entry);
}
if(zList){
insert(zList, -1);
}
}
}
void ZDLIWadList::addButton(){
QStringList filters;
filters << "WAD/PK3/ZIP (*.WAD *.pk3 *.zip)"
<< "WAD Files (*.WAD)"
<< "pk3 Files (*.pk3)"
<< "zip Files (*.zip)"
<< "All files (*)";
ZDLNameInput diag(this);
diag.setWindowTitle("Add IWAD");
diag.setFilter(filters);
if (diag.exec()){
QString fileName = diag.getFile();
QString name = diag.getName();
ZDLNameListable *zList = new ZDLNameListable(pList, 1001, fileName, name);
insert(zList, -1);
}
}
void ZDLIWadList::editButton(QListWidgetItem * item){
if (item){
QStringList filters;
filters << "WAD/PK3/ZIP (*.wad *.pk3 *.zip)"
<< "WAD Files (*.wad)"
<< "pk3 Files (*.pk3)"
<< "zip Files (*.zip)"
<< "All files (*)";
ZDLNameListable *zitem = (ZDLNameListable*)item;
ZDLNameInput diag(this);
diag.setWindowTitle("Add IWAD");
diag.setFilter(filters);
diag.basedOff(zitem);
if(diag.exec()){
QString fileName = diag.getFile();
QString name = diag.getName();
zitem->setDisplayName(name);
zitem->setFile(fileName);
}
}
}