Diffstat (limited to 'noncore/apps/checkbook/qcheckmainmenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/qcheckmainmenu.cpp | 143 |
1 files changed, 87 insertions, 56 deletions
diff --git a/noncore/apps/checkbook/qcheckmainmenu.cpp b/noncore/apps/checkbook/qcheckmainmenu.cpp index 2382513..1aead88 100644 --- a/noncore/apps/checkbook/qcheckmainmenu.cpp +++ b/noncore/apps/checkbook/qcheckmainmenu.cpp | |||
@@ -1,74 +1,105 @@ | |||
1 | #include "qcheckmainmenu.h" | 1 | #include "qcheckmainmenu.h" |
2 | #include "qcheckname.h" | 2 | #include "qcheckname.h" |
3 | 3 | ||
4 | QCheckMainMenu::QCheckMainMenu(QWidget *parent) | 4 | QCheckMainMenu::QCheckMainMenu(QWidget *parent) |
5 | : QCheckMMBase(parent) | 5 | : QCheckMMBase(parent) |
6 | { | 6 | { |
7 | init(); | 7 | init(); |
8 | } | 8 | } |
9 | 9 | ||
10 | void QCheckMainMenu::init() | 10 | void QCheckMainMenu::init() |
11 | { | 11 | { |
12 | lstCheckBooks->clear(); | 12 | lstCheckBooks->clear(); |
13 | QString checkdirname = QDir::homeDirPath(); | 13 | QString checkdirname = QDir::homeDirPath(); |
14 | checkdirname.append("/.checkbooks"); | 14 | checkdirname.append("/.checkbooks"); |
15 | QDir checkdir(checkdirname); | 15 | QDir checkdir(checkdirname); |
16 | if (checkdir.exists() == true) | 16 | if (checkdir.exists() == true) |
17 | { | 17 | { |
18 | QStringList checkbooks = checkdir.entryList("*.qcb", QDir::Files|QDir::Readable|QDir::Writable, QDir::Time); | 18 | QStringList checkbooks = checkdir.entryList("*.qcb", QDir::Files|QDir::Readable|QDir::Writable, QDir::Time); |
19 | for (QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++) | 19 | for (QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++) |
20 | { | 20 | { |
21 | (*it) = (*it).remove((*it).find('.'), (*it).length()); | 21 | (*it) = (*it).remove((*it).find('.'), (*it).length()); |
22 | } | 22 | } |
23 | lstCheckBooks->insertStringList(checkbooks); | 23 | lstCheckBooks->insertStringList(checkbooks); |
24 | } | 24 | } |
25 | lstCheckBooks->clearSelection(); | 25 | lstCheckBooks->clearSelection(); |
26 | connect(lstCheckBooks, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotSelected(QListBoxItem *))); | 26 | connect(lstCheckBooks, SIGNAL(clicked(QListBoxItem *)), this, SLOT(slotSelected(QListBoxItem *))); |
27 | lstCheckBooks->clearSelection(); | 27 | lstCheckBooks->clearSelection(); |
28 | } | 28 | } |
29 | 29 | ||
30 | void QCheckMainMenu::slotSelected(QListBoxItem *item) | 30 | void QCheckMainMenu::slotSelected(QListBoxItem *item) |
31 | { | 31 | { |
32 | if (item != 0) | 32 | if (item != 0) |
33 | { | 33 | { |
34 | QString text = item->text(); | 34 | QString text = item->text(); |
35 | if (text.isEmpty() == false) | 35 | if (text.isEmpty() == false) |
36 | { | 36 | { |
37 | text.append(".qcb"); | 37 | text.append(".qcb"); |
38 | QString checkdirname = QDir::homeDirPath(); | 38 | QString checkdirname = QDir::homeDirPath(); |
39 | checkdirname.append("/.checkbooks/"); | 39 | checkdirname.append("/.checkbooks/"); |
40 | text.prepend(checkdirname); | 40 | text.prepend(checkdirname); |
41 | emit itemSelected(text); | 41 | emit itemSelected(text); |
42 | } | 42 | } |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | void QCheckMainMenu::newClicked() | 46 | void QCheckMainMenu::newClicked() |
47 | { | 47 | { |
48 | QString checkname = QCheckName::getName(); | 48 | QString checkname = QCheckName::getName(); |
49 | if (checkname.isEmpty() == false) | 49 | if (checkname.isEmpty() == false) |
50 | { | 50 | { |
51 | QString checkdirname = QDir::homeDirPath(); | 51 | QString checkdirname = QDir::homeDirPath(); |
52 | checkdirname.append("/.checkbooks"); | 52 | checkdirname.append("/.checkbooks"); |
53 | QDir checkdir(checkdirname); | 53 | QDir checkdir(checkdirname); |
54 | if (checkdir.exists() == false) | 54 | if (checkdir.exists() == false) |
55 | { | 55 | { |
56 | checkdir.mkdir(checkdirname); | 56 | checkdir.mkdir(checkdirname); |
57 | } | 57 | } |
58 | checkdirname.append("/"); | 58 | checkdirname.append("/"); |
59 | checkdirname.append(checkname); | 59 | checkdirname.append(checkname); |
60 | checkdirname.append(".qcb"); | 60 | checkdirname.append(".qcb"); |
61 | QFile file(checkdirname); | 61 | QFile file(checkdirname); |
62 | if (file.exists() == false) | 62 | if (file.exists() == false) |
63 | { | 63 | { |
64 | file.open(IO_WriteOnly); | 64 | file.open(IO_WriteOnly); |
65 | QTextStream os(&file); | 65 | QTextStream os(&file); |
66 | os << ""; | 66 | os << ""; |
67 | file.close(); | 67 | file.close(); |
68 | } | 68 | } |
69 | QFileInfo fi(file); | 69 | QFileInfo fi(file); |
70 | QString noextension = fi.fileName(); | 70 | QString noextension = fi.fileName(); |
71 | noextension = noextension.remove(noextension.find('.'), noextension.length()); | 71 | noextension = noextension.remove(noextension.find('.'), noextension.length()); |
72 | lstCheckBooks->insertItem(noextension); | 72 | lstCheckBooks->insertItem(noextension); |
73 | } | 73 | } |
74 | } | ||
75 | |||
76 | void QCheckMainMenu::deleteClicked() | ||
77 | { | ||
78 | QString checkname = lstCheckBooks->currentText(); | ||
79 | if (checkname.isEmpty() == false) { | ||
80 | switch ( QMessageBox::warning(this,tr("Delete Account"),tr("Really delete the\n") | ||
81 | +checkname+tr(" account?") | ||
82 | ,tr("Yes"),tr("No"),0,1,1) ) { | ||
83 | case 0: { | ||
84 | |||
85 | QString checkdirname = QDir::homeDirPath(); | ||
86 | checkdirname.append("/.checkbooks"); | ||
87 | QDir checkdir(checkdirname); | ||
88 | QString checkDir=checkdirname; | ||
89 | |||
90 | checkdirname.append("/"); | ||
91 | checkdirname.append(checkname); | ||
92 | checkdirname.append(".qcb"); | ||
93 | QFile file(checkdirname); | ||
94 | if (file.exists() == true) { | ||
95 | if(!file.remove()) { | ||
96 | QMessageBox::message(tr("Checkbook"),tr("Could not remove account")); | ||
97 | return; | ||
98 | } else | ||
99 | lstCheckBooks->removeItem(lstCheckBooks->currentItem()); | ||
100 | } | ||
101 | } | ||
102 | break; | ||
103 | } | ||
104 | } | ||
74 | } | 105 | } |