|
Lines 1-628
Link Here
|
| 1 |
/* |
|
|
| 2 |
This file is part of KNewStuff. |
| 3 |
Copyright (c) 2003 Josef Spillner <spillner@kde.org> |
| 4 |
|
| 5 |
This library is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU Library General Public |
| 7 |
License as published by the Free Software Foundation; either |
| 8 |
version 2 of the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This library is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
Library General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Library General Public License |
| 16 |
along with this library; see the file COPYING.LIB. If not, write to |
| 17 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 |
Boston, MA 02110-1301, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "downloaddialog.h" |
| 22 |
#include "downloaddialog.moc" |
| 23 |
|
| 24 |
#include <tdelocale.h> |
| 25 |
#include <ktabctl.h> |
| 26 |
#include <tdelistview.h> |
| 27 |
#include <kdebug.h> |
| 28 |
#include <tdeio/job.h> |
| 29 |
#include <tdeio/netaccess.h> |
| 30 |
#include <tdemessagebox.h> |
| 31 |
#include <kurl.h> |
| 32 |
#include <tdeconfig.h> |
| 33 |
#include <tdeapplication.h> |
| 34 |
#include <kiconloader.h> |
| 35 |
|
| 36 |
#include <knewstuff/entry.h> |
| 37 |
#include <knewstuff/knewstuffgeneric.h> |
| 38 |
#include <knewstuff/engine.h> |
| 39 |
|
| 40 |
#include <tqlayout.h> |
| 41 |
#include <tqpushbutton.h> |
| 42 |
#include <tqdom.h> |
| 43 |
#include <tqlabel.h> |
| 44 |
#include <tqtextbrowser.h> |
| 45 |
#include <tqtimer.h> // hack |
| 46 |
|
| 47 |
using namespace KNS; |
| 48 |
|
| 49 |
class NumSortListViewItem : public TDEListViewItem |
| 50 |
{ |
| 51 |
public: |
| 52 |
NumSortListViewItem( TQListView * parent, TQString label1, TQString label2 = TQString(), TQString label3 = TQString(), TQString label4 = TQString(), TQString label5 = TQString(), TQString label6 = TQString(), TQString label7 = TQString(), TQString label8 = TQString() ) : |
| 53 |
TDEListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 ) |
| 54 |
{ |
| 55 |
} |
| 56 |
|
| 57 |
TQString key(int col, bool asc) const { |
| 58 |
if (col == 2) |
| 59 |
{ |
| 60 |
|
| 61 |
TQString s; |
| 62 |
s.sprintf("%08d", text(col).toInt()); |
| 63 |
return s; |
| 64 |
} |
| 65 |
return TDEListViewItem::key( col, asc ); |
| 66 |
} |
| 67 |
}; |
| 68 |
|
| 69 |
// BEGIN deprecated for KDE 4 |
| 70 |
DownloadDialog::DownloadDialog(Engine *engine, TQWidget *) |
| 71 |
: KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"), |
| 72 |
KDialogBase::Close, KDialogBase::Close) |
| 73 |
{ |
| 74 |
init(engine); |
| 75 |
} |
| 76 |
|
| 77 |
DownloadDialog::DownloadDialog(TQWidget *) |
| 78 |
: KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"), |
| 79 |
KDialogBase::Close, KDialogBase::Close) |
| 80 |
{ |
| 81 |
init(0); |
| 82 |
} |
| 83 |
|
| 84 |
void DownloadDialog::open(TQString type) |
| 85 |
{ |
| 86 |
DownloadDialog d; |
| 87 |
d.setType(type); |
| 88 |
d.load(); |
| 89 |
d.exec(); |
| 90 |
} |
| 91 |
// END deprecated for KDE 4 |
| 92 |
|
| 93 |
DownloadDialog::DownloadDialog(Engine *engine, TQWidget *, const TQString& caption) |
| 94 |
: KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption), |
| 95 |
KDialogBase::Close, KDialogBase::Close) |
| 96 |
{ |
| 97 |
init(engine); |
| 98 |
} |
| 99 |
|
| 100 |
DownloadDialog::DownloadDialog(TQWidget *, const TQString& caption) |
| 101 |
: KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption), |
| 102 |
KDialogBase::Close, KDialogBase::Close) |
| 103 |
{ |
| 104 |
init(0); |
| 105 |
} |
| 106 |
|
| 107 |
void DownloadDialog::init(Engine *engine) |
| 108 |
{ |
| 109 |
resize(700, 400); |
| 110 |
|
| 111 |
m_engine = engine; |
| 112 |
m_page = NULL; |
| 113 |
|
| 114 |
connect(this, TQT_SIGNAL(aboutToShowPage(TQWidget*)), TQT_SLOT(slotPage(TQWidget*))); |
| 115 |
|
| 116 |
if(!engine) |
| 117 |
{ |
| 118 |
m_loader = new ProviderLoader(this); |
| 119 |
connect(m_loader, TQT_SIGNAL(providersLoaded(Provider::List*)), TQT_SLOT(slotProviders(Provider::List*))); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
DownloadDialog::~DownloadDialog() |
| 124 |
{ |
| 125 |
} |
| 126 |
|
| 127 |
void DownloadDialog::load() |
| 128 |
{ |
| 129 |
m_loader->load(m_filter, m_providerlist); |
| 130 |
} |
| 131 |
|
| 132 |
void DownloadDialog::load(TQString providerList) |
| 133 |
{ |
| 134 |
m_loader->load(m_filter, providerList); |
| 135 |
} |
| 136 |
|
| 137 |
void DownloadDialog::clear() |
| 138 |
{ |
| 139 |
TQMap<TQWidget*, TQValueList<TDEListView*>* >::Iterator it; |
| 140 |
for(it = m_map.begin(); it != m_map.end(); ++it) |
| 141 |
{ |
| 142 |
TQValueList<TDEListView*> *v = it.data(); |
| 143 |
kdDebug() << "clear listviews in " << v << endl; |
| 144 |
if(v) |
| 145 |
{ |
| 146 |
(*(v->at(0)))->clear(); |
| 147 |
(*(v->at(1)))->clear(); |
| 148 |
(*(v->at(2)))->clear(); |
| 149 |
|
| 150 |
//delete (*it); |
| 151 |
} |
| 152 |
|
| 153 |
delete it.key(); |
| 154 |
} |
| 155 |
m_map.clear(); |
| 156 |
} |
| 157 |
|
| 158 |
void DownloadDialog::slotProviders(Provider::List *list) |
| 159 |
{ |
| 160 |
Provider *p; |
| 161 |
/*TQFrame *frame;*/ |
| 162 |
|
| 163 |
for(p = list->first(); p; p = list->next()) |
| 164 |
{ |
| 165 |
kdDebug() << "++ provider ++ " << p->name() << endl; |
| 166 |
|
| 167 |
if(!m_filter.isEmpty()) |
| 168 |
loadProvider(p); |
| 169 |
else |
| 170 |
addProvider(p); |
| 171 |
/*if(p == list->getFirst()) |
| 172 |
slotPage(m_frame);*/ // only if !qtbug |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
void DownloadDialog::addProvider(Provider *p) |
| 177 |
{ |
| 178 |
TQFrame *frame; |
| 179 |
KTabCtl *ctl; |
| 180 |
TQWidget *w_d, *w_r, *w_l; |
| 181 |
TQWidget *w2; |
| 182 |
TDEListView *lvtmp_r, *lvtmp_d, *lvtmp_l; |
| 183 |
TQTextBrowser *rt; |
| 184 |
TQString tmp; |
| 185 |
int ret; |
| 186 |
TQPixmap pix; |
| 187 |
|
| 188 |
if(m_map.count() == 0) |
| 189 |
{ |
| 190 |
frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap("")); |
| 191 |
delete frame; |
| 192 |
} |
| 193 |
|
| 194 |
kdDebug() << "addProvider()/begin" << endl; |
| 195 |
|
| 196 |
ret = true; |
| 197 |
if(!p->icon().isValid()) ret = false; |
| 198 |
else ret = TDEIO::NetAccess::download(p->icon(), tmp, this); |
| 199 |
if(ret) pix = TQPixmap(tmp); |
| 200 |
else pix = TDEGlobal::iconLoader()->loadIcon("knewstuff", TDEIcon::Panel); |
| 201 |
frame = addPage(p->name(), p->name(), pix); |
| 202 |
m_frame = frame; |
| 203 |
|
| 204 |
w2 = new TQWidget(frame); |
| 205 |
w_d = new TQWidget(frame); |
| 206 |
w_r = new TQWidget(frame); |
| 207 |
w_l = new TQWidget(frame); |
| 208 |
|
| 209 |
ctl = new KTabCtl(frame); |
| 210 |
ctl->addTab(w_r, i18n("Highest Rated")); |
| 211 |
ctl->addTab(w_d, i18n("Most Downloads")); |
| 212 |
ctl->addTab(w_l, i18n("Latest")); |
| 213 |
|
| 214 |
m_curtab = 0; |
| 215 |
connect(ctl, TQT_SIGNAL(tabSelected(int)), TQT_SLOT(slotTab(int))); |
| 216 |
|
| 217 |
TQHBoxLayout *box = new TQHBoxLayout(frame); |
| 218 |
box->add(ctl); |
| 219 |
|
| 220 |
lvtmp_r = new TDEListView(w_r); |
| 221 |
lvtmp_r->addColumn(i18n("Name")); |
| 222 |
lvtmp_r->addColumn(i18n("Version")); |
| 223 |
lvtmp_r->addColumn(i18n("Rating")); |
| 224 |
lvtmp_r->setSorting(2, false); |
| 225 |
|
| 226 |
lvtmp_d = new TDEListView(w_d); |
| 227 |
lvtmp_d->addColumn(i18n("Name")); |
| 228 |
lvtmp_d->addColumn(i18n("Version")); |
| 229 |
lvtmp_d->addColumn(i18n("Downloads")); |
| 230 |
lvtmp_d->setSorting(2, false); |
| 231 |
|
| 232 |
lvtmp_l = new TDEListView(w_l); |
| 233 |
lvtmp_l->addColumn(i18n("Name")); |
| 234 |
lvtmp_l->addColumn(i18n("Version")); |
| 235 |
lvtmp_l->addColumn(i18n("Release Date")); |
| 236 |
lvtmp_l->setSorting(2, false); |
| 237 |
|
| 238 |
connect(lvtmp_r, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected())); |
| 239 |
connect(lvtmp_d, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected())); |
| 240 |
connect(lvtmp_l, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected())); |
| 241 |
|
| 242 |
rt = new TQTextBrowser(frame); |
| 243 |
rt->setMinimumWidth(150); |
| 244 |
|
| 245 |
TQPushButton *in = new TQPushButton(i18n("Install"), frame); |
| 246 |
TQPushButton *de = new TQPushButton(i18n("Details"), frame); |
| 247 |
in->setEnabled(false); |
| 248 |
de->setEnabled(false); |
| 249 |
|
| 250 |
box->addSpacing(spacingHint()); |
| 251 |
TQVBoxLayout *vbox = new TQVBoxLayout(box); |
| 252 |
vbox->add(rt); |
| 253 |
vbox->addSpacing(spacingHint()); |
| 254 |
vbox->add(de); |
| 255 |
vbox->add(in); |
| 256 |
|
| 257 |
connect(in, TQT_SIGNAL(clicked()), TQT_SLOT(slotInstall())); |
| 258 |
connect(de, TQT_SIGNAL(clicked()), TQT_SLOT(slotDetails())); |
| 259 |
|
| 260 |
TQVBoxLayout *box2 = new TQVBoxLayout(w_r); |
| 261 |
box2->add(lvtmp_r); |
| 262 |
TQVBoxLayout *box3 = new TQVBoxLayout(w_d); |
| 263 |
box3->add(lvtmp_d); |
| 264 |
TQVBoxLayout *box4 = new TQVBoxLayout(w_l); |
| 265 |
box4->add(lvtmp_l); |
| 266 |
|
| 267 |
TQValueList<TDEListView*> *v = new TQValueList<TDEListView*>; |
| 268 |
*v << lvtmp_r << lvtmp_d << lvtmp_l; |
| 269 |
m_map[frame] = v; |
| 270 |
m_rts[frame] = rt; |
| 271 |
TQValueList<TQPushButton*> *vb = new TQValueList<TQPushButton*>; |
| 272 |
*vb << in << de; |
| 273 |
m_buttons[frame] = vb; |
| 274 |
m_providers[frame] = p; |
| 275 |
|
| 276 |
kdDebug() << "addProvider()/end; lvtmp_r = " << lvtmp_r << endl; |
| 277 |
|
| 278 |
if(m_engine) slotPage(frame); |
| 279 |
|
| 280 |
TQTimer::singleShot(100, this, TQT_SLOT(slotFinish())); |
| 281 |
} |
| 282 |
|
| 283 |
void DownloadDialog::slotResult(TDEIO::Job *job) |
| 284 |
{ |
| 285 |
TQDomDocument dom; |
| 286 |
TQDomElement knewstuff; |
| 287 |
|
| 288 |
kdDebug() << "got data: " << m_data[job] << endl; |
| 289 |
|
| 290 |
kapp->config()->setGroup("KNewStuffStatus"); |
| 291 |
|
| 292 |
dom.setContent(m_data[job]); |
| 293 |
knewstuff = dom.documentElement(); |
| 294 |
|
| 295 |
for(TQDomNode pn = knewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling()) |
| 296 |
{ |
| 297 |
TQDomElement stuff = pn.toElement(); |
| 298 |
|
| 299 |
kdDebug() << "element: " << stuff.tagName() << endl; |
| 300 |
|
| 301 |
if(stuff.tagName() == "stuff") |
| 302 |
{ |
| 303 |
Entry *entry = new Entry(stuff); |
| 304 |
kdDebug() << "TYPE::" << entry->type() << " FILTER::" << m_filter << endl; |
| 305 |
if(!entry->type().isEmpty()) |
| 306 |
{ |
| 307 |
if((!m_filter.isEmpty()) && (entry->type() != m_filter)) continue; |
| 308 |
} |
| 309 |
|
| 310 |
if((!m_filter.isEmpty()) && (m_jobs[job])) |
| 311 |
{ |
| 312 |
Provider *p = m_jobs[job]; |
| 313 |
addProvider(p); |
| 314 |
slotPage(m_frame); |
| 315 |
m_jobs[job] = 0; |
| 316 |
} |
| 317 |
addEntry(entry); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
m_data[job] = ""; |
| 322 |
} |
| 323 |
|
| 324 |
int DownloadDialog::installStatus(Entry *entry) |
| 325 |
{ |
| 326 |
TQDate date; |
| 327 |
TQString datestring; |
| 328 |
int installed; |
| 329 |
|
| 330 |
kapp->config()->setGroup("KNewStuffStatus"); |
| 331 |
datestring = kapp->config()->readEntry(entry->name()); |
| 332 |
if(datestring.isNull()) installed = 0; |
| 333 |
else |
| 334 |
{ |
| 335 |
date = TQDate::fromString(datestring, Qt::ISODate); |
| 336 |
if(!date.isValid()) installed = 0; |
| 337 |
else if(date < entry->releaseDate()) installed = -1; |
| 338 |
else installed = 1; |
| 339 |
} |
| 340 |
|
| 341 |
return installed; |
| 342 |
} |
| 343 |
|
| 344 |
void DownloadDialog::addEntry(Entry *entry) |
| 345 |
{ |
| 346 |
TQPixmap pix; |
| 347 |
int installed; |
| 348 |
|
| 349 |
/*if(m_engine) |
| 350 |
{ |
| 351 |
if(m_map.count() == 0) |
| 352 |
{ |
| 353 |
m_frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap("")); |
| 354 |
Provider *p = new Provider(); |
| 355 |
p->setName(i18n("Generic")); |
| 356 |
addProvider(p); |
| 357 |
slotPage(m_frame); |
| 358 |
} |
| 359 |
}*/ |
| 360 |
installed = installStatus(entry); |
| 361 |
|
| 362 |
if(installed > 0) pix = TDEGlobal::iconLoader()->loadIcon("ok", TDEIcon::Small); |
| 363 |
else if(installed < 0) pix = TDEGlobal::iconLoader()->loadIcon("history", TDEIcon::Small); |
| 364 |
else pix = TQPixmap(); |
| 365 |
|
| 366 |
TDEListViewItem *tmp_r = new TDEListViewItem(lv_r, |
| 367 |
entry->name(), entry->version(), TQString("%1").arg(entry->rating())); |
| 368 |
TDEListViewItem *tmp_d = new NumSortListViewItem(lv_d, |
| 369 |
entry->name(), entry->version(), TQString("%1").arg(entry->downloads())); |
| 370 |
TDEListViewItem *tmp_l = new TDEListViewItem(lv_l, |
| 371 |
entry->name(), entry->version(), TDEGlobal::locale()->formatDate(entry->releaseDate())); |
| 372 |
|
| 373 |
tmp_r->setPixmap(0, pix); |
| 374 |
tmp_d->setPixmap(0, pix); |
| 375 |
tmp_l->setPixmap(0, pix); |
| 376 |
|
| 377 |
m_entries.append(entry); |
| 378 |
|
| 379 |
kdDebug() << "added entry " << entry->name() << endl; |
| 380 |
} |
| 381 |
|
| 382 |
void DownloadDialog::slotData(TDEIO::Job *job, const TQByteArray &a) |
| 383 |
{ |
| 384 |
TQCString tmp(a, a.size() + 1); |
| 385 |
m_data[job].append(TQString::fromUtf8(tmp)); |
| 386 |
} |
| 387 |
|
| 388 |
void DownloadDialog::slotDetails() |
| 389 |
{ |
| 390 |
Entry *e = getEntry(); |
| 391 |
if(!e) return; |
| 392 |
|
| 393 |
TQString lang = TDEGlobal::locale()->language(); |
| 394 |
|
| 395 |
TQString info = i18n |
| 396 |
( |
| 397 |
"Name: %1\n" |
| 398 |
"Author: %2\n" |
| 399 |
"License: %3\n" |
| 400 |
"Version: %4\n" |
| 401 |
"Release: %5\n" |
| 402 |
"Rating: %6\n" |
| 403 |
"Downloads: %7\n" |
| 404 |
"Release date: %8\n" |
| 405 |
"Summary: %9\n" |
| 406 |
).arg(e->name() |
| 407 |
).arg(e->author() |
| 408 |
).arg(e->license() |
| 409 |
).arg(e->version() |
| 410 |
).arg(e->release() |
| 411 |
).arg(e->rating() |
| 412 |
).arg(e->downloads() |
| 413 |
).arg(TDEGlobal::locale()->formatDate(e->releaseDate()) |
| 414 |
).arg(e->summary(lang) |
| 415 |
); |
| 416 |
|
| 417 |
info.append(i18n |
| 418 |
( |
| 419 |
"Preview: %1\n" |
| 420 |
"Payload: %2\n" |
| 421 |
).arg(e->preview().url() |
| 422 |
).arg(e->payload().url() |
| 423 |
)); |
| 424 |
|
| 425 |
KMessageBox::information(this, info, i18n("Details")); |
| 426 |
} |
| 427 |
|
| 428 |
void DownloadDialog::slotInstall() |
| 429 |
{ |
| 430 |
Entry *e = getEntry(); |
| 431 |
if(!e) return; |
| 432 |
|
| 433 |
kdDebug() << "download entry now" << endl; |
| 434 |
|
| 435 |
if(m_engine) |
| 436 |
{ |
| 437 |
m_engine->download(e); |
| 438 |
install(e); |
| 439 |
} |
| 440 |
else |
| 441 |
{ |
| 442 |
m_s = new KNewStuffGeneric(e->type(), this); |
| 443 |
|
| 444 |
m_entry = e; |
| 445 |
|
| 446 |
KURL source = e->payload(); |
| 447 |
KURL dest = KURL(m_s->downloadDestination(e)); |
| 448 |
|
| 449 |
TDEIO::FileCopyJob *job = TDEIO::file_copy(source, dest, -1, true); |
| 450 |
connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotInstalled(TDEIO::Job*))); |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
void DownloadDialog::install(Entry *e) |
| 455 |
{ |
| 456 |
kapp->config()->setGroup("KNewStuffStatus"); |
| 457 |
kapp->config()->writeEntry(m_entryname, e->releaseDate().toString(Qt::ISODate)); |
| 458 |
kapp->config()->sync(); |
| 459 |
|
| 460 |
TQPixmap pix = TDEGlobal::iconLoader()->loadIcon("ok", TDEIcon::Small); |
| 461 |
m_entryitem = lv_r->findItem(m_entryname, 0); |
| 462 |
if(m_entryitem) m_entryitem->setPixmap(0, pix); |
| 463 |
m_entryitem = lv_d->findItem(m_entryname, 0); |
| 464 |
if(m_entryitem) m_entryitem->setPixmap(0, pix); |
| 465 |
m_entryitem = lv_l->findItem(m_entryname, 0); |
| 466 |
if(m_entryitem) m_entryitem->setPixmap(0, pix); |
| 467 |
|
| 468 |
|
| 469 |
TQPushButton *in; |
| 470 |
in = *(m_buttons[m_page]->at(0)); |
| 471 |
if(in) in->setEnabled(false); |
| 472 |
} |
| 473 |
|
| 474 |
void DownloadDialog::slotInstalled(TDEIO::Job *job) |
| 475 |
{ |
| 476 |
bool ret = (job->error() == 0); |
| 477 |
TDEIO::FileCopyJob *cjob; |
| 478 |
|
| 479 |
if(ret) |
| 480 |
{ |
| 481 |
cjob = static_cast<TDEIO::FileCopyJob*>(job); |
| 482 |
if(cjob) |
| 483 |
{ |
| 484 |
ret = m_s->install(cjob->destURL().path()); |
| 485 |
} |
| 486 |
else ret = false; |
| 487 |
} |
| 488 |
|
| 489 |
if(ret) |
| 490 |
{ |
| 491 |
install(m_entry); |
| 492 |
|
| 493 |
KMessageBox::information(this, i18n("Installation successful."), i18n("Installation")); |
| 494 |
} |
| 495 |
else KMessageBox::error(this, i18n("Installation failed."), i18n("Installation")); |
| 496 |
|
| 497 |
delete m_s; |
| 498 |
} |
| 499 |
|
| 500 |
void DownloadDialog::slotTab(int tab) |
| 501 |
{ |
| 502 |
kdDebug() << "switch tab to: " << tab << endl; |
| 503 |
m_curtab = tab; |
| 504 |
} |
| 505 |
|
| 506 |
void DownloadDialog::slotSelected() |
| 507 |
{ |
| 508 |
TQString tmp; |
| 509 |
bool enabled; |
| 510 |
Entry *e = getEntry(); |
| 511 |
TQString lang = TDEGlobal::locale()->language(); |
| 512 |
|
| 513 |
if(e) |
| 514 |
{ |
| 515 |
if(!e->preview(lang).isValid()) |
| 516 |
{ |
| 517 |
m_rt->setText(TQString("<b>%1</b><br>%2<br>%3<br><br><i>%4</i><br>(%5)").arg( |
| 518 |
e->name()).arg(e->author()).arg(TDEGlobal::locale()->formatDate(e->releaseDate())).arg(e->summary(lang)).arg(e->license())); |
| 519 |
} |
| 520 |
else |
| 521 |
{ |
| 522 |
TDEIO::NetAccess::download(e->preview(lang), tmp, this); |
| 523 |
m_rt->setText(TQString("<b>%1</b><br>%2<br>%3<br><br><img src='%4'><br><i>%5</i><br>(%6)").arg( |
| 524 |
e->name()).arg(e->author()).arg(TDEGlobal::locale()->formatDate(e->releaseDate())).arg(tmp).arg(e->summary(lang)).arg(e->license())); |
| 525 |
} |
| 526 |
|
| 527 |
if(installStatus(e) == 1) enabled = false; |
| 528 |
else enabled = true; |
| 529 |
|
| 530 |
TQPushButton *de, *in; |
| 531 |
in = *(m_buttons[m_page]->at(0)); |
| 532 |
de = *(m_buttons[m_page]->at(1)); |
| 533 |
if(in) in->setEnabled(enabled); |
| 534 |
if(de) de->setEnabled(true); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
Entry *DownloadDialog::getEntry() |
| 539 |
{ |
| 540 |
if(m_curtab == 0) m_entryitem = lv_r->currentItem(); |
| 541 |
else if(m_curtab == 1) m_entryitem = lv_d->currentItem(); |
| 542 |
else if(m_curtab == 2) m_entryitem = lv_l->currentItem(); |
| 543 |
else return 0; |
| 544 |
|
| 545 |
m_entryname = m_entryitem->text(0); |
| 546 |
|
| 547 |
for(Entry *e = m_entries.first(); e; e = m_entries.next()) |
| 548 |
{ |
| 549 |
if(e->name() == m_entryname) return e; |
| 550 |
} |
| 551 |
|
| 552 |
return 0; |
| 553 |
} |
| 554 |
|
| 555 |
void DownloadDialog::slotPage(TQWidget *w) |
| 556 |
{ |
| 557 |
Provider *p; |
| 558 |
|
| 559 |
kdDebug() << "changed widget!!!" << endl; |
| 560 |
|
| 561 |
if(m_map.find(w) == m_map.end()) return; |
| 562 |
|
| 563 |
m_page = w; |
| 564 |
|
| 565 |
lv_r = *(m_map[w]->at(0)); |
| 566 |
lv_d = *(m_map[w]->at(1)); |
| 567 |
lv_l = *(m_map[w]->at(2)); |
| 568 |
p = m_providers[w]; |
| 569 |
m_rt = m_rts[w]; |
| 570 |
|
| 571 |
kdDebug() << "valid change!!!; lv_r = " << lv_r << endl; |
| 572 |
|
| 573 |
if(m_engine) return; |
| 574 |
|
| 575 |
if(!m_filter.isEmpty()) return; |
| 576 |
|
| 577 |
lv_r->clear(); |
| 578 |
lv_d->clear(); |
| 579 |
lv_l->clear(); |
| 580 |
|
| 581 |
kdDebug() << "-- fetch -- " << p->downloadUrl() << endl; |
| 582 |
|
| 583 |
loadProvider(p); |
| 584 |
} |
| 585 |
|
| 586 |
void DownloadDialog::loadProvider(Provider *p) |
| 587 |
{ |
| 588 |
TDEIO::TransferJob *job = TDEIO::get(p->downloadUrl()); |
| 589 |
|
| 590 |
m_jobs[job] = p; |
| 591 |
|
| 592 |
connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*))); |
| 593 |
connect(job, TQT_SIGNAL(data(TDEIO::Job*, const TQByteArray&)), |
| 594 |
TQT_SLOT(slotData(TDEIO::Job*, const TQByteArray&))); |
| 595 |
} |
| 596 |
|
| 597 |
void DownloadDialog::setType(TQString type) |
| 598 |
{ |
| 599 |
m_filter = type; |
| 600 |
} |
| 601 |
|
| 602 |
void DownloadDialog::setProviderList(const TQString& providerList) |
| 603 |
{ |
| 604 |
m_providerlist = providerList; |
| 605 |
} |
| 606 |
|
| 607 |
void DownloadDialog::slotOk() |
| 608 |
{ |
| 609 |
} |
| 610 |
|
| 611 |
void DownloadDialog::slotApply() |
| 612 |
{ |
| 613 |
} |
| 614 |
|
| 615 |
void DownloadDialog::open(const TQString& type, const TQString& caption) |
| 616 |
{ |
| 617 |
DownloadDialog d(0, caption); |
| 618 |
d.setType(type); |
| 619 |
d.load(); |
| 620 |
d.exec(); |
| 621 |
} |
| 622 |
|
| 623 |
void DownloadDialog::slotFinish() |
| 624 |
{ |
| 625 |
showPage(1); |
| 626 |
//updateBackground(); |
| 627 |
} |
| 628 |
|