updated on Thu Jan 26 00:18:00 UTC 2012
[aur-mirror.git] / klibido / klibido.diff
blobde82668c919e5ee9859c18a24f06dbfff7e57dc1
1 diff -ru klibido-0.2.5-orig/src/klibido.cpp klibido-0.2.5/src/klibido.cpp
2 --- klibido-0.2.5-orig/src/klibido.cpp 2006-03-04 11:29:01.000000000 +0100
3 +++ klibido-0.2.5/src/klibido.cpp 2009-10-08 10:49:38.000000000 +0200
4 @@ -38,7 +38,7 @@
5 // // #include <kaction.h>
6 #include <kprogress.h>
7 #include <kdeversion.h>
9 +#include <ksystemtray.h>
10 #include <kglobal.h>
13 @@ -46,7 +46,7 @@
16 klibido::klibido()
17 - : KMdiMainFrm( 0, "KLibido" ,KMdi::IDEAlMode )
18 + : KMdiMainFrm( 0, "KLibido" ,KMdi::IDEAlMode ), m_quit(false)
21 // set the shell's ui resource file
22 @@ -78,8 +78,11 @@
24 else migrateDbs();
28 + //setup systemtray icon
29 + systemTray = new KSystemTray(this);
30 + systemTray->setPixmap(systemTray->loadIcon("klibido"));
31 + connect(systemTray, SIGNAL(quitSelected()), this, SLOT(quit()));
32 + systemTray->show();
33 // setupServers();
36 @@ -438,15 +441,13 @@
44 void klibido::quit()
46 /// @todo implement me
47 // return;
48 // this->close();
49 + m_quit = true;
51 if (close() )
52 kapp->quit();
54 @@ -1636,21 +1637,29 @@
56 void klibido::closeEvent( QCloseEvent * e )
58 - if (qMgr->empty()) {
59 - saveSize("MainWindow");
60 - e->accept();
61 + if(m_quit)
62 + {
63 + if (qMgr->empty()) {
64 + saveSize("MainWindow");
65 + e->accept();
67 - } else {
68 - int result=KMessageBox::questionYesNo(this, i18n("The download queue is not empty. Are you sure you want to quit?"), i18n("question"));
69 - switch (result) {
70 - case KMessageBox::Yes:
71 - saveSize("MainWindow");
72 - e->accept();
73 - break;
74 - case KMessageBox::No:
75 - break;
76 + } else {
77 + int result=KMessageBox::questionYesNo(this, i18n("The download queue is not empty. Are you sure you want to quit?"), i18n("question"));
78 + switch (result) {
79 + case KMessageBox::Yes:
80 + saveSize("MainWindow");
81 + e->accept();
82 + break;
83 + case KMessageBox::No:
84 + m_quit = false;
85 + break;
86 + }
89 + else
90 + {
91 + hide();
92 + }
95 void klibido::slotQPaused( bool paused)
96 @@ -2093,5 +2102,15 @@
100 +bool klibido::queryClose()
102 + kdDebug() << "queryClose() returning " << m_quit;
103 + if(!m_quit)
105 + hide();
108 + return m_quit;
111 #include "klibido.moc"
112 diff -ru klibido-0.2.5-orig/src/klibido.h klibido-0.2.5/src/klibido.h
113 --- klibido-0.2.5-orig/src/klibido.h 2006-02-09 11:01:19.000000000 +0100
114 +++ klibido-0.2.5/src/klibido.h 2009-10-07 23:49:11.000000000 +0200
115 @@ -54,6 +54,7 @@
116 class ServersList;
117 class AvailableGroups;
118 class FileViewer;
119 +class KSystemTray;
120 //Toolbar...
123 @@ -131,7 +132,8 @@
124 KAccel *accel;
125 KPopupMenu *wMenu;
126 KAction *closeAction;
128 + KSystemTray *systemTray;
129 + bool m_quit;
131 //Statusbar widget
132 // QLabel *tLabel;
133 @@ -189,6 +191,9 @@
135 virtual ~klibido();
137 +protected:
138 + virtual bool queryClose();
140 public slots:
141 //void openNewWindow();
142 void slotOpenNewsGroup(NewsGroup *ng);
143 diff -ru klibido-0.2.5-orig/src/qmgr.cpp klibido-0.2.5/src/qmgr.cpp
144 --- klibido-0.2.5-orig/src/qmgr.cpp 2006-02-12 09:04:51.000000000 +0100
145 +++ klibido-0.2.5/src/qmgr.cpp 2009-10-07 21:31:08.000000000 +0200
146 @@ -2570,138 +2570,143 @@
148 void QMgr::slotOpenNzb( )
150 - QString nzbFilename = KFileDialog::getOpenFileName(QString::null, "*.nzb|Newzbin Files\n", this, i18n("Open a .nzb file"));
151 - kdDebug() << "Opened " << nzbFilename << endl;
153 - if (nzbFilename.isNull())
154 - return;
156 - //Parse nzb and add posts to the queue
157 - //Ok, I should create a separate class...but for now, let's try a quick & dirty solution...
158 - //Code taken (and adapted with permission) from knzb, (C) 2004 David Pye.
160 - QFile nzbFile(nzbFilename);
161 - if (!nzbFile.open(IO_ReadOnly)) {
162 - //TODO: Error messagebox!
163 - return;
165 - QMap<int, BinHeader*> headerMap;
166 - int i=0;
168 - QDomDocument doc("nzbfile");
169 - BinHeader *bh = NULL;
170 - doc.setContent(&nzbFile);
171 - nzbFile.close();
172 - QFileInfo qf(nzbFilename);
173 - QRegExp rx("\\((\\d+)/(\\d+)\\)");
174 - QDomElement docElem = doc.documentElement();
175 - QDomNode n = docElem.firstChild();
177 - while (!n.isNull()) {
179 - QDomElement e = n.toElement();
180 - if (!e.isNull()) {
181 - if (e.tagName() = "file") {
182 - //Create a BinHeader
183 - i++;
184 - bh = new BinHeader();
185 - QString subject = e.attribute("subject");
186 - int pos=0;
187 - int capPart=0;
188 - int capTotal=0;
189 - int index=-1; // = rx.search(h->m_subj, -1);
190 - while ( (pos=rx.search(subject, pos)) != -1 ) {
191 - index=pos;
192 - pos+=rx.matchedLength();
193 - capPart=rx.cap(1).toInt();
194 - capTotal=rx.cap(2).toInt();
196 - subject=subject.left(index).simplifyWhiteSpace();
197 - bh->setSubj(subject);
199 - bh->setFrom(e.attribute("poster"));
200 - QDateTime qdt;
201 - qdt.setTime_t(e.attribute("date").toUInt());
202 - bh->setDate(qdt.toTime_t());
203 - bh->setStatus(BinHeader::bh_new);
204 - bh->setNumParts(capTotal);
205 - QDomNode fileSubNode = e.firstChild();
206 - while (!fileSubNode.isNull()) {
207 - QDomElement fileElement = fileSubNode.toElement();
208 - if (!fileElement.isNull()) {
209 - if (fileElement.tagName()=="segments") {
210 - QDomNode segmentsSubNode = fileSubNode.firstChild();
211 - while (!segmentsSubNode.isNull()) {
212 - QDomElement segmentsElement = segmentsSubNode.toElement();
213 - if (!segmentsElement.isNull()) {
214 - if (segmentsElement.tagName()=="segment") {
215 - int bytes = segmentsElement.attribute("bytes").toInt();
216 - int part = segmentsElement.attribute("number").toInt();
217 - QString mid = segmentsElement.text();
218 - bh->addNzbPart(part, bytes, mid);
219 - Servers::Iterator sit;
220 - for (sit = servers->begin(); sit != servers->end(); ++sit) {
221 - bh->addHost(part, sit.key());
222 + QStringList nzbFilenames = KFileDialog::getOpenFileNames(QString::null, "*.nzb|Newzbin Files\n", this, i18n("Open .nzb files"));
223 + QStringList::iterator it;
225 + for(it = nzbFilenames.begin(); it != nzbFilenames.end(); it++)
227 + QString nzbFilename = *it;
228 + kdDebug() << "Opened " << nzbFilename << endl;
230 + if (nzbFilename.isNull())
231 + continue;
233 + //Parse nzb and add posts to the queue
234 + //Ok, I should create a separate class...but for now, let's try a quick & dirty solution...
235 + //Code taken (and adapted with permission) from knzb, (C) 2004 David Pye.
237 + QFile nzbFile(nzbFilename);
238 + if (!nzbFile.open(IO_ReadOnly)) {
239 + //TODO: Error messagebox!
240 + continue;
242 + QMap<int, BinHeader*> headerMap;
243 + int i=0;
245 + QDomDocument doc("nzbfile");
246 + BinHeader *bh = NULL;
247 + doc.setContent(&nzbFile);
248 + nzbFile.close();
249 + QFileInfo qf(nzbFilename);
250 + QRegExp rx("\\((\\d+)/(\\d+)\\)");
251 + QDomElement docElem = doc.documentElement();
252 + QDomNode n = docElem.firstChild();
254 + while (!n.isNull()) {
256 + QDomElement e = n.toElement();
257 + if (!e.isNull()) {
258 + if (e.tagName() = "file") {
259 + //Create a BinHeader
260 + i++;
261 + bh = new BinHeader();
262 + QString subject = e.attribute("subject");
263 + int pos=0;
264 + int capPart=0;
265 + int capTotal=0;
266 + int index=-1; // = rx.search(h->m_subj, -1);
267 + while ( (pos=rx.search(subject, pos)) != -1 ) {
268 + index=pos;
269 + pos+=rx.matchedLength();
270 + capPart=rx.cap(1).toInt();
271 + capTotal=rx.cap(2).toInt();
273 + subject=subject.left(index).simplifyWhiteSpace();
274 + bh->setSubj(subject);
276 + bh->setFrom(e.attribute("poster"));
277 + QDateTime qdt;
278 + qdt.setTime_t(e.attribute("date").toUInt());
279 + bh->setDate(qdt.toTime_t());
280 + bh->setStatus(BinHeader::bh_new);
281 + bh->setNumParts(capTotal);
282 + QDomNode fileSubNode = e.firstChild();
283 + while (!fileSubNode.isNull()) {
284 + QDomElement fileElement = fileSubNode.toElement();
285 + if (!fileElement.isNull()) {
286 + if (fileElement.tagName()=="segments") {
287 + QDomNode segmentsSubNode = fileSubNode.firstChild();
288 + while (!segmentsSubNode.isNull()) {
289 + QDomElement segmentsElement = segmentsSubNode.toElement();
290 + if (!segmentsElement.isNull()) {
291 + if (segmentsElement.tagName()=="segment") {
292 + int bytes = segmentsElement.attribute("bytes").toInt();
293 + int part = segmentsElement.attribute("number").toInt();
294 + QString mid = segmentsElement.text();
295 + bh->addNzbPart(part, bytes, mid);
296 + Servers::Iterator sit;
297 + for (sit = servers->begin(); sit != servers->end(); ++sit) {
298 + bh->addHost(part, sit.key());
302 + segmentsSubNode = segmentsSubNode.nextSibling();
304 - segmentsSubNode = segmentsSubNode.nextSibling();
308 + fileSubNode=fileSubNode.nextSibling();
311 - fileSubNode=fileSubNode.nextSibling();
315 + //BEGIN DEBUG!
316 + // kdDebug() << "Binheader created!" << endl;
317 + // kdDebug() << "Subject: " << bh->getSubj() << endl;
318 + // kdDebug() << "From: " << bh->getFrom() << endl;
319 + // kdDebug() << "Bytes: " << bh->getSize() << endl;
320 + // kdDebug() << "Parts: " << bh->getParts() << endl;
321 + // PartMid::Iterator pit;
322 + // for (pit=bh->partMid.begin() ; pit != bh->partMid.end(); ++pit) {
323 + // kdDebug() << "Part: " << pit.key() << " mid: " << pit.data() << endl;
324 + // }
325 + //END DEBUG
327 + headerMap[i]=bh;
329 + //Insert binheader into nzb group...
330 + /*
331 + Dbt key, data;
332 + memset(&key, 0, sizeof(key));
333 + memset(&data, 0, sizeof(data));
336 + QString index=bh->getSubj().simplifyWhiteSpace() + bh->getFrom();
337 + kdDebug() << "Saving " << index << endl;
339 + key.set_data((void*) (const char *) index);
340 + key.set_size(index.length());
341 + data.set_data(bh->data() );
342 + data.set_size(bh->getRecordSize());
343 + int ret;
344 + if ( (ret = nzbGroup->getDb()->put(0, &key, &data, 0) ) != 0)
345 + kdDebug() << "Error inserting binheader into nzbGroup: " << dbEnv->strerror(ret) << endl;
347 + free(data.get_data());
350 + slotAddPostItem(bh, nzbGroup, false,false);
351 + */
353 - //BEGIN DEBUG!
354 -// kdDebug() << "Binheader created!" << endl;
355 -// kdDebug() << "Subject: " << bh->getSubj() << endl;
356 -// kdDebug() << "From: " << bh->getFrom() << endl;
357 -// kdDebug() << "Bytes: " << bh->getSize() << endl;
358 -// kdDebug() << "Parts: " << bh->getParts() << endl;
359 -// PartMid::Iterator pit;
360 -// for (pit=bh->partMid.begin() ; pit != bh->partMid.end(); ++pit) {
361 -// kdDebug() << "Part: " << pit.key() << " mid: " << pit.data() << endl;
362 -// }
363 - //END DEBUG
365 - headerMap[i]=bh;
367 - //Insert binheader into nzb group...
368 - /*
369 - Dbt key, data;
370 - memset(&key, 0, sizeof(key));
371 - memset(&data, 0, sizeof(data));
374 - QString index=bh->getSubj().simplifyWhiteSpace() + bh->getFrom();
375 - kdDebug() << "Saving " << index << endl;
377 - key.set_data((void*) (const char *) index);
378 - key.set_size(index.length());
379 - data.set_data(bh->data() );
380 - data.set_size(bh->getRecordSize());
381 - int ret;
382 - if ( (ret = nzbGroup->getDb()->put(0, &key, &data, 0) ) != 0)
383 - kdDebug() << "Error inserting binheader into nzbGroup: " << dbEnv->strerror(ret) << endl;
385 - free(data.get_data());
388 - slotAddPostItem(bh, nzbGroup, false,false);
389 - */
390 + n=n.nextSibling();
392 - n=n.nextSibling();
393 + QFileInfo fi(nzbFilename);
395 + NzbForm *nzbForm = new NzbForm(&headerMap, nzbGroup->getSaveDir() + fi.baseName(true), this, nzbFilename, true);
396 + connect(nzbForm, SIGNAL(sigDownloadNzbPost(BinHeader*, bool, QString )), this, SLOT(slotAddNzbItem(BinHeader*, bool, QString)));
397 + nzbForm->exec();
399 + nzbGroup->getDb()->sync(0);
401 - QFileInfo fi(nzbFilename);
403 - NzbForm *nzbForm = new NzbForm(&headerMap, nzbGroup->getSaveDir() + fi.baseName(true), this, nzbFilename, true);
404 - connect(nzbForm, SIGNAL(sigDownloadNzbPost(BinHeader*, bool, QString )), this, SLOT(slotAddNzbItem(BinHeader*, bool, QString)));
405 - nzbForm->exec();
407 - nzbGroup->getDb()->sync(0);