-
Notifications
You must be signed in to change notification settings - Fork 42
/
ZDLFileList.cpp
150 lines (130 loc) · 3.83 KB
/
ZDLFileList.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* 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 "ZDLFileList.h"
#include "ZDLFileListable.h"
#include "ZDLListWidget.h"
#include "zdlconf.h"
#include "ZDLMapFile.h"
#include "disabled.h"
#include <qvariant.h>
extern QString getLastDir();
extern void saveLastDir(QString fileName);
ZDLFileList::ZDLFileList(ZDLWidget *parent): ZDLListWidget(parent){
}
void ZDLFileList::newDrop(QStringList fileList){
for (int i = 0; i < fileList.size(); i++) {
ZDLFileListable *zList = new ZDLFileListable(pList, 1001, fileList[i]);
zList->enable();
insert(zList, -1);
}
}
void ZDLFileList::newConfig(){
QString disabled;
pList->clear();
auto zconf = ZDLConfigurationManager::getActiveConfiguration();
if (zconf->contains(disabledKey))
{
disabled = zconf->value(disabledKey).toString();
}
for (int i = 0; ; i++)
{
QString key("zdl.save/file%1");
key = key.arg(i);
if (!zconf->contains(key))
{
break;
}
ZDLFileListable *zList = new ZDLFileListable(pList, 1001, zconf->value(key).toString());
/* disabled in constructor */
if (!disabledScan(disabled, i))
{
zList->enable();
}
insert(zList, -1);
}
}
void ZDLFileList::rebuild(){
QStringList disabled;
auto zconf = ZDLConfigurationManager::getActiveConfiguration();
for (int i = 0; ; i++)
{
QString key("zdl.save/file%1");
key = key.arg(i);
if (!zconf->contains(key))
{
break;
}
zconf->remove(key);
}
if (zconf->contains(disabledKey))
{
zconf->remove(disabledKey);
}
for(int i = 0; i < count(); i++){
QListWidgetItem *itm = pList->item(i);
ZDLFileListable* fitm = (ZDLFileListable*)itm;
QString name = QString("file%1").arg(QString::number(i));
zconf->setValue("zdl.save/" + name, fitm->getFile());
if (!fitm->state())
{
disabled << QString::number(i);
}
}
if (disabled.size() > 0)
{
zconf->setValue(disabledKey, disabled.join(","));
}
}
void ZDLFileList::addButton(){
QStringList filters;
filters << "WAD/PK3/ZIP/PK7/PKZ/P7Z (*.wad *.WAD *.pk3 *.PK3 *.zip *.ZIP *.pk7 *.PK7 *.pkz *.PKZ *.p7z *.P7Z *.ipk3 *.IPK3)"
<< "WAD Files (*.wad *.WAD)"
<< "PK3 Files (*.pk3 *.PK3)"
<< "IPK3 Files (*.ipk3 *.IPK3)"
<< "Patch Files (*.bex *.deh *.BEX *.DEH)"
<< "PK7 Files (*.pk7 *.PK7)"
<< "PKZ Files (*.pkz *.PKZ)"
<< "P7Z Files (*.p7z *.P7Z)"
<< "zip Files (*.zip *.ZIP)"
<< "Any files (*)";
QStringList fileNames = QFileDialog::getOpenFileNames(this, "Add File", getLastDir(), filters.join(";;"));
for(int i = 0; i < fileNames.size(); i++){
saveLastDir(fileNames[i]);
ZDLFileListable *zList = new ZDLFileListable(pList, 1001, fileNames[i]);
zList->enable();
insert(zList, -1);
}
}
void ZDLFileList::remove(int index) {
ZDLListWidget::remove(index);
QString keyBase { "file%1" };
QSettings* conf = ZDLConfigurationManager::getActiveConfiguration();
// Move following files back by one, and remove the last.
for (int curIndex = index;; curIndex++) {
int nextIndex = curIndex + 1;
QString curKey = keyBase.arg(curIndex);
QString nextKey = keyBase.arg(nextIndex);
if (!conf->contains(curKey)) { break; }
if (conf->contains(nextKey)) {
QVariant nextValue = conf->value(nextKey);
conf->setValue(curKey, nextValue);
} else {
conf->remove(curKey);
}
}
}