-
Notifications
You must be signed in to change notification settings - Fork 7
/
exportoofiledialog.cpp
90 lines (77 loc) · 1.96 KB
/
exportoofiledialog.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
#include "exportoofiledialog.h"
ExportOOFileDialog::ExportOOFileDialog():QFileDialog()
{
init();
}
ExportOOFileDialog::ExportOOFileDialog (QWidget * parent, const QString &caption ):QFileDialog(parent, caption)
{
init();
}
bool ExportOOFileDialog::foundConfig()
{
return !filters.isEmpty();
}
QString ExportOOFileDialog::selectedConfig()
{
QStringList::Iterator itpath=configPaths.begin();
QStringList::Iterator itf=filters.begin();
while (itf != filters.end())
{
if (*itf==selectedNameFilter()) return *itpath;
itpath++;
itf++;
}
qWarning ("ExportOOFileDialog::selectedConfig No filter found!");
return "";
}
void ExportOOFileDialog::newConfigPath(const QString &s)
{
lastFilter=s;
}
void ExportOOFileDialog::show()
{
setNameFilters (filters);
QFileDialog::show();
}
void ExportOOFileDialog::init()
{
setFileMode( QFileDialog::AnyFile );
QDir d;
d.setPath ("/usr/share/vym/exports");
scanExportConfigs(d);
d.setPath (d.homePath()+"/.vym/exports");
scanExportConfigs(d);
d.setPath (d.currentPath()+"/exports");
scanExportConfigs(d);
setNameFilters (filters);
connect (
this,SIGNAL (filterSelected(const QString&)),
this, SLOT( newConfigPath(const QString &)));
}
void ExportOOFileDialog::addFilter(const QString &f)
{
lastFilter=f;
filters.append (f);
}
void ExportOOFileDialog::scanExportConfigs(QDir dir)
{
// Scan existing export configurations
SimpleSettings set;
QFile f;
if (dir.exists())
{
// Traverse files
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QFileInfo fi = list.at(i);
if (fi.fileName().endsWith(".conf") )
{
configPaths.append (fi.absoluteFilePath());
set.clear();
set.readSettings (fi.absoluteFilePath());
addFilter (set.value (QString("Name")) + " (*.odp)");
}
}
}
}