parent
e85d9aa121
commit
76c59a3384
@ -1,13 +0,0 @@
|
||||
AM_CPPFLAGS = -I$(srcdir)/.. $(all_includes)
|
||||
|
||||
METASOURCES = AUTO
|
||||
|
||||
noinst_LTLIBRARIES = libknewstuff.la
|
||||
|
||||
libknewstuff_la_LDFLAGS = $(all_libraries)
|
||||
libknewstuff_la_LIBADD = $(LIB_TDEIO)
|
||||
libknewstuff_la_SOURCES = engine.cpp entry.cpp downloaddialog.cpp \
|
||||
uploaddialog.cpp providerdialog.cpp provider.cpp knewstuff.cpp \
|
||||
knewstuffgeneric.cpp knewstuffsecure.cpp security.cpp
|
||||
|
||||
KDE_ICON=AUTO
|
Before Width: | Height: | Size: 710 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 3.1 KiB |
@ -1,628 +0,0 @@
|
||||
/*
|
||||
This file is part of KNewStuff.
|
||||
Copyright (c) 2003 Josef Spillner <spillner@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "downloaddialog.h"
|
||||
#include "downloaddialog.moc"
|
||||
|
||||
#include <tdelocale.h>
|
||||
#include <ktabctl.h>
|
||||
#include <tdelistview.h>
|
||||
#include <kdebug.h>
|
||||
#include <tdeio/job.h>
|
||||
#include <tdeio/netaccess.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <kurl.h>
|
||||
#include <tdeconfig.h>
|
||||
#include <tdeapplication.h>
|
||||
#include <kiconloader.h>
|
||||
|
||||
#include <knewstuff/entry.h>
|
||||
#include <knewstuff/knewstuffgeneric.h>
|
||||
#include <knewstuff/engine.h>
|
||||
|
||||
#include <tqlayout.h>
|
||||
#include <tqpushbutton.h>
|
||||
#include <tqdom.h>
|
||||
#include <tqlabel.h>
|
||||
#include <tqtextbrowser.h>
|
||||
#include <tqtimer.h> // hack
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
class NumSortListViewItem : public TDEListViewItem
|
||||
{
|
||||
public:
|
||||
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() ) :
|
||||
TDEListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
|
||||
{
|
||||
}
|
||||
|
||||
TQString key(int col, bool asc) const {
|
||||
if (col == 2)
|
||||
{
|
||||
|
||||
TQString s;
|
||||
s.sprintf("%08d", text(col).toInt());
|
||||
return s;
|
||||
}
|
||||
return TDEListViewItem::key( col, asc );
|
||||
}
|
||||
};
|
||||
|
||||
// BEGIN deprecated for KDE 4
|
||||
DownloadDialog::DownloadDialog(Engine *engine, TQWidget *)
|
||||
: KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
|
||||
KDialogBase::Close, KDialogBase::Close)
|
||||
{
|
||||
init(engine);
|
||||
}
|
||||
|
||||
DownloadDialog::DownloadDialog(TQWidget *)
|
||||
: KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
|
||||
KDialogBase::Close, KDialogBase::Close)
|
||||
{
|
||||
init(0);
|
||||
}
|
||||
|
||||
void DownloadDialog::open(TQString type)
|
||||
{
|
||||
DownloadDialog d;
|
||||
d.setType(type);
|
||||
d.load();
|
||||
d.exec();
|
||||
}
|
||||
// END deprecated for KDE 4
|
||||
|
||||
DownloadDialog::DownloadDialog(Engine *engine, TQWidget *, const TQString& caption)
|
||||
: KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
|
||||
KDialogBase::Close, KDialogBase::Close)
|
||||
{
|
||||
init(engine);
|
||||
}
|
||||
|
||||
DownloadDialog::DownloadDialog(TQWidget *, const TQString& caption)
|
||||
: KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
|
||||
KDialogBase::Close, KDialogBase::Close)
|
||||
{
|
||||
init(0);
|
||||
}
|
||||
|
||||
void DownloadDialog::init(Engine *engine)
|
||||
{
|
||||
resize(700, 400);
|
||||
|
||||
m_engine = engine;
|
||||
m_page = NULL;
|
||||
|
||||
connect(this, TQT_SIGNAL(aboutToShowPage(TQWidget*)), TQT_SLOT(slotPage(TQWidget*)));
|
||||
|
||||
if(!engine)
|
||||
{
|
||||
m_loader = new ProviderLoader(this);
|
||||
connect(m_loader, TQT_SIGNAL(providersLoaded(Provider::List*)), TQT_SLOT(slotProviders(Provider::List*)));
|
||||
}
|
||||
}
|
||||
|
||||
DownloadDialog::~DownloadDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void DownloadDialog::load()
|
||||
{
|
||||
m_loader->load(m_filter, m_providerlist);
|
||||
}
|
||||
|
||||
void DownloadDialog::load(TQString providerList)
|
||||
{
|
||||
m_loader->load(m_filter, providerList);
|
||||
}
|
||||
|
||||
void DownloadDialog::clear()
|
||||
{
|
||||
TQMap<TQWidget*, TQValueList<TDEListView*>* >::Iterator it;
|
||||
for(it = m_map.begin(); it != m_map.end(); ++it)
|
||||
{
|
||||
TQValueList<TDEListView*> *v = it.data();
|
||||
kdDebug() << "clear listviews in " << v << endl;
|
||||
if(v)
|
||||
{
|
||||
(*(v->at(0)))->clear();
|
||||
(*(v->at(1)))->clear();
|
||||
(*(v->at(2)))->clear();
|
||||
|
||||
//delete (*it);
|
||||
}
|
||||
|
||||
delete it.key();
|
||||
}
|
||||
m_map.clear();
|
||||
}
|
||||
|
||||
void DownloadDialog::slotProviders(Provider::List *list)
|
||||
{
|
||||
Provider *p;
|
||||
/*TQFrame *frame;*/
|
||||
|
||||
for(p = list->first(); p; p = list->next())
|
||||
{
|
||||
kdDebug() << "++ provider ++ " << p->name() << endl;
|
||||
|
||||
if(!m_filter.isEmpty())
|
||||
loadProvider(p);
|
||||
else
|
||||
addProvider(p);
|
||||
/*if(p == list->getFirst())
|
||||
slotPage(m_frame);*/ // only if !qtbug
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadDialog::addProvider(Provider *p)
|
||||
{
|
||||
TQFrame *frame;
|
||||
KTabCtl *ctl;
|
||||
TQWidget *w_d, *w_r, *w_l;
|
||||
TQWidget *w2;
|
||||
TDEListView *lvtmp_r, *lvtmp_d, *lvtmp_l;
|
||||
TQTextBrowser *rt;
|
||||
TQString tmp;
|
||||
int ret;
|
||||
TQPixmap pix;
|
||||
|
||||
if(m_map.count() == 0)
|
||||
{
|
||||
frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap(""));
|
||||
delete frame;
|
||||
}
|
||||
|
||||
kdDebug() << "addProvider()/begin" << endl;
|
||||
|
||||
ret = true;
|
||||
if(!p->icon().isValid()) ret = false;
|
||||
else ret = TDEIO::NetAccess::download(p->icon(), tmp, this);
|
||||
if(ret) pix = TQPixmap(tmp);
|
||||
else pix = TDEGlobal::iconLoader()->loadIcon("knewstuff", TDEIcon::Panel);
|
||||
frame = addPage(p->name(), p->name(), pix);
|
||||
m_frame = frame;
|
||||
|
||||
w2 = new TQWidget(frame);
|
||||
w_d = new TQWidget(frame);
|
||||
w_r = new TQWidget(frame);
|
||||
w_l = new TQWidget(frame);
|
||||
|
||||
ctl = new KTabCtl(frame);
|
||||
ctl->addTab(w_r, i18n("Highest Rated"));
|
||||
ctl->addTab(w_d, i18n("Most Downloads"));
|
||||
ctl->addTab(w_l, i18n("Latest"));
|
||||
|
||||
m_curtab = 0;
|
||||
connect(ctl, TQT_SIGNAL(tabSelected(int)), TQT_SLOT(slotTab(int)));
|
||||
|
||||
TQHBoxLayout *box = new TQHBoxLayout(frame);
|
||||
box->add(ctl);
|
||||
|
||||
lvtmp_r = new TDEListView(w_r);
|
||||
lvtmp_r->addColumn(i18n("Name"));
|
||||
lvtmp_r->addColumn(i18n("Version"));
|
||||
lvtmp_r->addColumn(i18n("Rating"));
|
||||
lvtmp_r->setSorting(2, false);
|
||||
|
||||
lvtmp_d = new TDEListView(w_d);
|
||||
lvtmp_d->addColumn(i18n("Name"));
|
||||
lvtmp_d->addColumn(i18n("Version"));
|
||||
lvtmp_d->addColumn(i18n("Downloads"));
|
||||
lvtmp_d->setSorting(2, false);
|
||||
|
||||
lvtmp_l = new TDEListView(w_l);
|
||||
lvtmp_l->addColumn(i18n("Name"));
|
||||
lvtmp_l->addColumn(i18n("Version"));
|
||||
lvtmp_l->addColumn(i18n("Release Date"));
|
||||
lvtmp_l->setSorting(2, false);
|
||||
|
||||
connect(lvtmp_r, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
|
||||
connect(lvtmp_d, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
|
||||
connect(lvtmp_l, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
|
||||
|
||||
rt = new TQTextBrowser(frame);
|
||||
rt->setMinimumWidth(150);
|
||||
|
||||
TQPushButton *in = new TQPushButton(i18n("Install"), frame);
|
||||
TQPushButton *de = new TQPushButton(i18n("Details"), frame);
|
||||
in->setEnabled(false);
|
||||
de->setEnabled(false);
|
||||
|
||||
box->addSpacing(spacingHint());
|
||||
TQVBoxLayout *vbox = new TQVBoxLayout(box);
|
||||
vbox->add(rt);
|
||||
vbox->addSpacing(spacingHint());
|
||||
vbox->add(de);
|
||||
vbox->add(in);
|
||||
|
||||
connect(in, TQT_SIGNAL(clicked()), TQT_SLOT(slotInstall()));
|
||||
connect(de, TQT_SIGNAL(clicked()), TQT_SLOT(slotDetails()));
|
||||
|
||||
TQVBoxLayout *box2 = new TQVBoxLayout(w_r);
|
||||
box2->add(lvtmp_r);
|
||||
TQVBoxLayout *box3 = new TQVBoxLayout(w_d);
|
||||
box3->add(lvtmp_d);
|
||||
TQVBoxLayout *box4 = new TQVBoxLayout(w_l);
|
||||
box4->add(lvtmp_l);
|
||||
|
||||
TQValueList<TDEListView*> *v = new TQValueList<TDEListView*>;
|
||||
*v << lvtmp_r << lvtmp_d << lvtmp_l;
|
||||
m_map[frame] = v;
|
||||
m_rts[frame] = rt;
|
||||
TQValueList<TQPushButton*> *vb = new TQValueList<TQPushButton*>;
|
||||
*vb << in << de;
|
||||
m_buttons[frame] = vb;
|
||||
m_providers[frame] = p;
|
||||
|
||||
kdDebug() << "addProvider()/end; lvtmp_r = " << lvtmp_r << endl;
|
||||
|
||||
if(m_engine) slotPage(frame);
|
||||
|
||||
TQTimer::singleShot(100, this, TQT_SLOT(slotFinish()));
|
||||
}
|
||||
|
||||
void DownloadDialog::slotResult(TDEIO::Job *job)
|
||||
{
|
||||
TQDomDocument dom;
|
||||
TQDomElement knewstuff;
|
||||
|
||||
kdDebug() << "got data: " << m_data[job] << endl;
|
||||
|
||||
kapp->config()->setGroup("KNewStuffStatus");
|
||||
|
||||
dom.setContent(m_data[job]);
|
||||
knewstuff = dom.documentElement();
|
||||
|
||||
for(TQDomNode pn = knewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling())
|
||||
{
|
||||
TQDomElement stuff = pn.toElement();
|
||||
|
||||
kdDebug() << "element: " << stuff.tagName() << endl;
|
||||
|
||||
if(stuff.tagName() == "stuff")
|
||||
{
|
||||
Entry *entry = new Entry(stuff);
|
||||
kdDebug() << "TYPE::" << entry->type() << " FILTER::" << m_filter << endl;
|
||||
if(!entry->type().isEmpty())
|
||||
{
|
||||
if((!m_filter.isEmpty()) && (entry->type() != m_filter)) continue;
|
||||
}
|
||||
|
||||
if((!m_filter.isEmpty()) && (m_jobs[job]))
|
||||
{
|
||||
Provider *p = m_jobs[job];
|
||||
addProvider(p);
|
||||
slotPage(m_frame);
|
||||
m_jobs[job] = 0;
|
||||
}
|
||||
addEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
m_data[job] = "";
|
||||
}
|
||||
|
||||
int DownloadDialog::installStatus(Entry *entry)
|
||||
{
|
||||
TQDate date;
|
||||
TQString datestring;
|
||||
int installed;
|
||||
|
||||
kapp->config()->setGroup("KNewStuffStatus");
|
||||
datestring = kapp->config()->readEntry(entry->name());
|
||||
if(datestring.isNull()) installed = 0;
|
||||
else
|
||||
{
|
||||
date = TQDate::fromString(datestring, Qt::ISODate);
|
||||
if(!date.isValid()) installed = 0;
|
||||
else if(date < entry->releaseDate()) installed = -1;
|
||||
else installed = 1;
|
||||
}
|
||||
|
||||
return installed;
|
||||
}
|
||||
|
||||
void DownloadDialog::addEntry(Entry *entry)
|
||||
{
|
||||
TQPixmap pix;
|
||||
int installed;
|
||||
|
||||
/*if(m_engine)
|
||||
{
|
||||
if(m_map.count() == 0)
|
||||
{
|
||||
m_frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap(""));
|
||||
Provider *p = new Provider();
|
||||
p->setName(i18n("Generic"));
|
||||
addProvider(p);
|
||||
slotPage(m_frame);
|
||||
}
|
||||
}*/
|
||||
installed = installStatus(entry);
|
||||
|
||||
if(installed > 0) pix = TDEGlobal::iconLoader()->loadIcon("ok", TDEIcon::Small);
|
||||
else if(installed < 0) pix = TDEGlobal::iconLoader()->loadIcon("history", TDEIcon::Small);
|
||||
else pix = TQPixmap();
|
||||
|
||||
TDEListViewItem *tmp_r = new TDEListViewItem(lv_r,
|
||||
entry->name(), entry->version(), TQString("%1").arg(entry->rating()));
|
||||
TDEListViewItem *tmp_d = new NumSortListViewItem(lv_d,
|
||||
entry->name(), entry->version(), TQString("%1").arg(entry->downloads()));
|
||||
TDEListViewItem *tmp_l = new TDEListViewItem(lv_l,
|
||||
entry->name(), entry->version(), TDEGlobal::locale()->formatDate(entry->releaseDate()));
|
||||
|
||||
tmp_r->setPixmap(0, pix);
|
||||
tmp_d->setPixmap(0, pix);
|
||||
tmp_l->setPixmap(0, pix);
|
||||
|
||||
m_entries.append(entry);
|
||||
|
||||
kdDebug() << "added entry " << entry->name() << endl;
|
||||
}
|
||||
|
||||
void DownloadDialog::slotData(TDEIO::Job *job, const TQByteArray &a)
|
||||
{
|
||||
TQCString tmp(a, a.size() + 1);
|
||||
m_data[job].append(TQString::fromUtf8(tmp));
|
||||
}
|
||||
|
||||
void DownloadDialog::slotDetails()
|
||||
{
|
||||
Entry *e = getEntry();
|
||||
if(!e) return;
|
||||
|
||||
TQString lang = TDEGlobal::locale()->language();
|
||||
|
||||
TQString info = i18n
|
||||
(
|
||||
"Name: %1\n"
|
||||
"Author: %2\n"
|
||||
"License: %3\n"
|
||||
"Version: %4\n"
|
||||
"Release: %5\n"
|
||||
"Rating: %6\n"
|
||||
"Downloads: %7\n"
|
||||
"Release date: %8\n"
|
||||
"Summary: %9\n"
|
||||
).arg(e->name()
|
||||
).arg(e->author()
|
||||
).arg(e->license()
|
||||
).arg(e->version()
|
||||
).arg(e->release()
|
||||
).arg(e->rating()
|
||||
).arg(e->downloads()
|
||||
).arg(TDEGlobal::locale()->formatDate(e->releaseDate())
|
||||
).arg(e->summary(lang)
|
||||
);
|
||||
|
||||
info.append(i18n
|
||||
(
|
||||
"Preview: %1\n"
|
||||
"Payload: %2\n"
|
||||
).arg(e->preview().url()
|
||||
).arg(e->payload().url()
|
||||
));
|
||||
|
||||
KMessageBox::information(this, info, i18n("Details"));
|
||||
}
|
||||
|
||||
void DownloadDialog::slotInstall()
|
||||
{
|
||||
Entry *e = getEntry();
|
||||
if(!e) return;
|
||||
|
||||
kdDebug() << "download entry now" << endl;
|
||||
|
||||
if(m_engine)
|
||||
{
|
||||
m_engine->download(e);
|
||||
install(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_s = new KNewStuffGeneric(e->type(), this);
|
||||
|
||||
m_entry = e;
|
||||
|
||||
KURL source = e->payload();
|
||||
KURL dest = KURL(m_s->downloadDestination(e));
|
||||
|
||||
TDEIO::FileCopyJob *job = TDEIO::file_copy(source, dest, -1, true);
|
||||
connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotInstalled(TDEIO::Job*)));
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadDialog::install(Entry *e)
|
||||
{
|
||||
kapp->config()->setGroup("KNewStuffStatus");
|
||||
kapp->config()->writeEntry(m_entryname, e->releaseDate().toString(Qt::ISODate));
|
||||
kapp->config()->sync();
|
||||
|
||||
TQPixmap pix = TDEGlobal::iconLoader()->loadIcon("ok", TDEIcon::Small);
|
||||
m_entryitem = lv_r->findItem(m_entryname, 0);
|
||||
if(m_entryitem) m_entryitem->setPixmap(0, pix);
|
||||
m_entryitem = lv_d->findItem(m_entryname, 0);
|
||||
if(m_entryitem) m_entryitem->setPixmap(0, pix);
|
||||
m_entryitem = lv_l->findItem(m_entryname, 0);
|
||||
if(m_entryitem) m_entryitem->setPixmap(0, pix);
|
||||
|
||||
|
||||
TQPushButton *in;
|
||||
in = *(m_buttons[m_page]->at(0));
|
||||
if(in) in->setEnabled(false);
|
||||
}
|
||||
|
||||
void DownloadDialog::slotInstalled(TDEIO::Job *job)
|
||||
{
|
||||
bool ret = (job->error() == 0);
|
||||
TDEIO::FileCopyJob *cjob;
|
||||
|
||||
if(ret)
|
||||
{
|
||||
cjob = static_cast<TDEIO::FileCopyJob*>(job);
|
||||
if(cjob)
|
||||
{
|
||||
ret = m_s->install(cjob->destURL().path());
|
||||
}
|
||||
else ret = false;
|
||||
}
|
||||
|
||||
if(ret)
|
||||
{
|
||||
install(m_entry);
|
||||
|
||||
KMessageBox::information(this, i18n("Installation successful."), i18n("Installation"));
|
||||
}
|
||||
else KMessageBox::error(this, i18n("Installation failed."), i18n("Installation"));
|
||||
|
||||
delete m_s;
|
||||
}
|
||||
|
||||
void DownloadDialog::slotTab(int tab)
|
||||
{
|
||||
kdDebug() << "switch tab to: " << tab << endl;
|
||||
m_curtab = tab;
|
||||
}
|
||||
|
||||
void DownloadDialog::slotSelected()
|
||||
{
|
||||
TQString tmp;
|
||||
bool enabled;
|
||||
Entry *e = getEntry();
|
||||
TQString lang = TDEGlobal::locale()->language();
|
||||
|
||||
if(e)
|
||||
{
|
||||
if(!e->preview(lang).isValid())
|
||||
{
|
||||
m_rt->setText(TQString("<b>%1</b><br>%2<br>%3<br><br><i>%4</i><br>(%5)").arg(
|
||||
e->name()).arg(e->author()).arg(TDEGlobal::locale()->formatDate(e->releaseDate())).arg(e->summary(lang)).arg(e->license()));
|
||||
}
|
||||
else
|
||||
{
|
||||
TDEIO::NetAccess::download(e->preview(lang), tmp, this);
|
||||
m_rt->setText(TQString("<b>%1</b><br>%2<br>%3<br><br><img src='%4'><br><i>%5</i><br>(%6)").arg(
|
||||
e->name()).arg(e->author()).arg(TDEGlobal::locale()->formatDate(e->releaseDate())).arg(tmp).arg(e->summary(lang)).arg(e->license()));
|
||||
}
|
||||
|
||||
if(installStatus(e) == 1) enabled = false;
|
||||
else enabled = true;
|
||||
|
||||
TQPushButton *de, *in;
|
||||
in = *(m_buttons[m_page]->at(0));
|
||||
de = *(m_buttons[m_page]->at(1));
|
||||
if(in) in->setEnabled(enabled);
|
||||
if(de) de->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Entry *DownloadDialog::getEntry()
|
||||
{
|
||||
if(m_curtab == 0) m_entryitem = lv_r->currentItem();
|
||||
else if(m_curtab == 1) m_entryitem = lv_d->currentItem();
|
||||
else if(m_curtab == 2) m_entryitem = lv_l->currentItem();
|
||||
else return 0;
|
||||
|
||||
m_entryname = m_entryitem->text(0);
|
||||
|
||||
for(Entry *e = m_entries.first(); e; e = m_entries.next())
|
||||
{
|
||||
if(e->name() == m_entryname) return e;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DownloadDialog::slotPage(TQWidget *w)
|
||||
{
|
||||
Provider *p;
|
||||
|
||||
kdDebug() << "changed widget!!!" << endl;
|
||||
|
||||
if(m_map.find(w) == m_map.end()) return;
|
||||
|
||||
m_page = w;
|
||||
|
||||
lv_r = *(m_map[w]->at(0));
|
||||
lv_d = *(m_map[w]->at(1));
|
||||
lv_l = *(m_map[w]->at(2));
|
||||
p = m_providers[w];
|
||||
m_rt = m_rts[w];
|
||||
|
||||
kdDebug() << "valid change!!!; lv_r = " << lv_r << endl;
|
||||
|
||||
if(m_engine) return;
|
||||
|
||||
if(!m_filter.isEmpty()) return;
|
||||
|
||||
lv_r->clear();
|
||||
lv_d->clear();
|
||||
lv_l->clear();
|
||||
|
||||
kdDebug() << "-- fetch -- " << p->downloadUrl() << endl;
|
||||
|
||||
loadProvider(p);
|
||||
}
|
||||
|
||||
void DownloadDialog::loadProvider(Provider *p)
|
||||
{
|
||||
TDEIO::TransferJob *job = TDEIO::get(p->downloadUrl());
|
||||
|
||||
m_jobs[job] = p;
|
||||
|
||||
connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
|
||||
connect(job, TQT_SIGNAL(data(TDEIO::Job*, const TQByteArray&)),
|
||||
TQT_SLOT(slotData(TDEIO::Job*, const TQByteArray&)));
|
||||
}
|
||||
|
||||
void DownloadDialog::setType(TQString type)
|
||||
{
|
||||
m_filter = type;
|
||||
}
|
||||
|
||||
void DownloadDialog::setProviderList(const TQString& providerList)
|
||||
{
|
||||
m_providerlist = providerList;
|
||||
}
|
||||
|
||||
void DownloadDialog::slotOk()
|
||||
{
|
||||
}
|
||||
|
||||
void DownloadDialog::slotApply()
|
||||
{
|
||||
}
|
||||
|
||||
void DownloadDialog::open(const TQString& type, const TQString& caption)
|
||||
{
|
||||
DownloadDialog d(0, caption);
|
||||
d.setType(type);
|
||||
d.load();
|
||||
d.exec();
|
||||
}
|
||||
|
||||
void DownloadDialog::slotFinish()
|
||||
{
|
||||
showPage(1);
|
||||
//updateBackground();
|
||||
}
|
||||
|
@ -1,238 +0,0 @@
|
||||
/*
|
||||
This file is part of KNewStuff.
|
||||
Copyright (c) 2003 Josef Spillner <spillner@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_DOWNLOADDIALOG_H
|
||||
#define KNEWSTUFF_DOWNLOADDIALOG_H
|
||||
|
||||
#include <kdialogbase.h>
|
||||
#include <knewstuff/provider.h>
|
||||
|
||||
namespace TDEIO
|
||||
{
|
||||
class Job;
|
||||
}
|
||||
|
||||
class TDEListView;
|
||||
class TQTextBrowser;
|
||||
class TQFrame;
|
||||
class KNewStuffGeneric;
|
||||
|
||||
namespace KNS
|
||||
{
|
||||
|
||||
class ProviderLoader;
|
||||
class Entry;
|
||||
class Provider;
|
||||
class Engine;
|
||||
|
||||
/**
|
||||
* @short Common download dialog for data browsing and installation.
|
||||
*
|
||||
* It provides an easy-to-use convenience method named open() which does all
|
||||
* the work, unless a more complex operation is needed.
|
||||
* \code
|
||||
* KNewStuff::DownloadDialog::open("kdesktop/wallpapers");
|
||||
* \endcode
|
||||
*
|
||||
* @author Josef Spillner (spillner@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class KDE_EXPORT DownloadDialog : public KDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param engine a pre-built engine object, or NULL if the download
|
||||
dialog should create an engine on its own
|
||||
@param parent the parent window
|
||||
@param caption the dialog caption
|
||||
*/
|
||||
DownloadDialog(Engine *engine, TQWidget *parent, const TQString& caption);
|
||||
|
||||
/**
|
||||
Alternative constructor.
|
||||
Always uses an internal engine.
|
||||
|
||||
@param parent the parent window
|
||||
@param caption the dialog caption
|
||||
*/
|
||||
DownloadDialog(TQWidget *parent, const TQString& caption);
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
*/
|
||||
~DownloadDialog();
|
||||
|
||||
/**
|
||||
Restricts the display of available data to a certain data type.
|
||||
|
||||
@param type a Hotstuff data type such as "korganizer/calendar"
|
||||
*/
|
||||
void setType(TQString type);
|
||||
// ### KDE 4.0: use const TQString&
|
||||
|
||||
/**
|
||||
Fetches descriptions of all available data, optionally considering
|
||||
a previously set type.
|
||||
*/
|
||||
void load();
|
||||
|
||||
/**
|
||||
Explicitly uses this provider list instead of the one read from
|
||||
the application configuration.
|
||||
|
||||
@param providerList the URL of the provider list
|
||||
|
||||
@since 3.4
|
||||
*/
|
||||
void setProviderList(const TQString& providerList);
|
||||
|
||||
/**
|
||||
Fetches descriptions of all available data, optionally considering
|
||||
a previously set type.
|
||||
|
||||
@param providerList the URl to the list of providers; if empty
|
||||
we first try the ProvidersUrl from TDEGlobal::config, then we
|
||||
fall back to a hardcoded value.
|
||||
*/
|
||||
void load(TQString providerList); // KDE4: merge with load() above
|
||||
|
||||
/**
|
||||
Adds another provider to the download dialog.
|
||||
This is normally done internally.
|
||||
|
||||
@param p the Hotstuff provider to be added
|
||||
*/
|
||||
void addProvider(Provider *p);
|
||||
|
||||
/**
|
||||
Adds an additional entry to the current provider.
|
||||
This is normally done internally.
|
||||
|
||||
@param entry a Hotstuff data entry to be added
|
||||
*/
|
||||
void addEntry(Entry *entry);
|
||||
|
||||
/**
|
||||
Clears the entry list of the current provider.
|
||||
This is normally done internally.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
Opens the download dialog.
|
||||
This is a convenience method which automatically sets up the dialog.
|
||||
@see setType()
|
||||
@see load()
|
||||
|
||||
@param type a data type such as "korganizer/calendar"
|
||||
@param caption the dialog caption
|
||||
*/
|
||||
static void open(const TQString& type, const TQString& caption);
|
||||
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param engine a pre-built engine object, or NULL if the download
|
||||
dialog should create an engine on its own
|
||||
@param parent the parent window
|
||||
*/
|
||||
DownloadDialog(Engine *engine, TQWidget *parent = 0);
|
||||
// ### KDE 4.0: remove and make caption/parent argument optional
|
||||
|
||||
/**
|
||||
Alternative constructor.
|
||||
Always uses an internal engine.
|
||||
|
||||
@param parent the parent window
|
||||
*/
|
||||
DownloadDialog(TQWidget *parent = 0);
|
||||
// ### KDE 4.0: remove and make caption/parent argument optional
|
||||
|
||||
/**
|
||||
Opens the download dialog.
|
||||
This is a convenience method which automatically sets up the dialog.
|
||||
@see setType()
|
||||
@see load()
|
||||
|
||||
@param type a data type such as "korganizer/calendar"
|
||||
*/
|
||||
static void open(TQString type);
|
||||
// ### KDE 4.0: remove and make caption/parent argument optional
|
||||
|
||||
public slots:
|
||||
/**
|
||||
Availability of the provider list.
|
||||
|
||||
@param list list of Hotstuff providers
|
||||
*/
|
||||
void slotProviders(Provider::List *list);
|
||||
|
||||
protected slots:
|
||||
void slotApply();
|
||||
void slotOk();
|
||||
|
||||
private slots:
|
||||
void slotResult(TDEIO::Job *job);
|
||||
void slotData(TDEIO::Job *job, const TQByteArray &a);
|
||||
void slotInstall();
|
||||
void slotDetails();
|
||||
void slotInstalled(TDEIO::Job *job);
|
||||
void slotTab(int tab);
|
||||
void slotSelected();
|
||||
void slotPage(TQWidget *w);
|
||||
void slotFinish();
|
||||
|
||||
private:
|
||||
void init(Engine *e);
|
||||
Entry *getEntry();
|
||||
void loadProvider(Provider *p);
|
||||
void install(Entry *e);
|
||||
int installStatus(Entry *e);
|
||||
|
||||
ProviderLoader *m_loader;
|
||||
TQString m_entryname;
|
||||
TDEListView *lv_r, *lv_d, *lv_l;
|
||||
TQTextBrowser *m_rt;
|
||||
TQFrame *m_frame;
|
||||
TQListViewItem *m_entryitem;
|
||||
TQPtrList<Entry> m_entries;
|
||||
Entry *m_entry;
|
||||
KNewStuffGeneric *m_s;
|
||||
int m_curtab;
|
||||
TQMap<TQWidget*, TQValueList<TDEListView*>* > m_map;
|
||||
TQMap<TQWidget*, Provider*> m_providers;
|
||||
TQMap<TQWidget*, TQTextBrowser*> m_rts;
|
||||
TQMap<TQWidget*, TQValueList<TQPushButton*>* > m_buttons;
|
||||
TQMap<TDEIO::Job*, Provider*> m_jobs;
|
||||
TQMap<TDEIO::Job*, TQString> m_data;
|
||||
TQString m_filter;
|
||||
TQString m_providerlist;
|
||||
Engine *m_engine;
|
||||
TQWidget *m_page;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,420 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tqcstring.h>
|
||||
#include <tqdom.h>
|
||||
#include <tqfileinfo.h>
|
||||
|
||||
#include <tdeapplication.h>
|
||||
#include <kdebug.h>
|
||||
#include <tdeio/job.h>
|
||||
#include <tdelocale.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <kstandarddirs.h>
|
||||
|
||||
#include "knewstuff.h"
|
||||
#include "downloaddialog.h"
|
||||
#include "uploaddialog.h"
|
||||
#include "providerdialog.h"
|
||||
|
||||
#include "engine.h"
|
||||
#include "engine.moc"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
Engine::Engine( KNewStuff *newStuff, const TQString &type,
|
||||
TQWidget *parentWidget ) :
|
||||
mParentWidget( parentWidget ), mDownloadDialog( 0 ),
|
||||
mUploadDialog( 0 ), mProviderDialog( 0 ), mUploadProvider( 0 ),
|
||||
mNewStuff( newStuff ), mType( type )
|
||||
{
|
||||
mProviderLoader = new ProviderLoader( mParentWidget );
|
||||
|
||||
mNewStuffList.setAutoDelete( true );
|
||||
}
|
||||
|
||||
Engine::Engine( KNewStuff *newStuff, const TQString &type,
|
||||
const TQString &providerList, TQWidget *parentWidget ) :
|
||||
mParentWidget( parentWidget ),
|
||||
mDownloadDialog( 0 ), mUploadDialog( 0 ),
|
||||
mProviderDialog( 0 ), mUploadProvider( 0 ),
|
||||
mProviderList( providerList ), mNewStuff( newStuff ),
|
||||
mType( type )
|
||||
{
|
||||
mProviderLoader = new ProviderLoader( mParentWidget );
|
||||
mNewStuffList.setAutoDelete( true );
|
||||
}
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
delete mProviderLoader;
|
||||
|
||||
delete mUploadDialog;
|
||||
delete mDownloadDialog;
|
||||
}
|
||||
|
||||
void Engine::download()
|
||||
{
|
||||
kdDebug(5850) << "Engine::download()" << endl;
|
||||
|
||||
connect( mProviderLoader,
|
||||
TQT_SIGNAL( providersLoaded( Provider::List * ) ),
|
||||
TQT_SLOT( getMetaInformation( Provider::List * ) ) );
|
||||
mProviderLoader->load( mType, mProviderList );
|
||||
}
|
||||
|
||||
void Engine::getMetaInformation( Provider::List *providers )
|
||||
{
|
||||
mProviderLoader->disconnect();
|
||||
|
||||
mNewStuffJobData.clear();
|
||||
|
||||
if ( !mDownloadDialog ) {
|
||||
mDownloadDialog = new DownloadDialog( this, mParentWidget );
|
||||
mDownloadDialog->show();
|
||||
}
|
||||
mDownloadDialog->clear();
|
||||
|
||||
Provider *p;
|
||||
for ( p = providers->first(); p; p = providers->next() ) {
|
||||
if ( p->downloadUrl().isEmpty() ) continue;
|
||||
|
||||
TDEIO::TransferJob *job = TDEIO::get( p->downloadUrl() );
|
||||
connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||||
TQT_SLOT( slotNewStuffJobResult( TDEIO::Job * ) ) );
|
||||
connect( job, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ),
|
||||
TQT_SLOT( slotNewStuffJobData( TDEIO::Job *, const TQByteArray & ) ) );
|
||||
|
||||
mNewStuffJobData.insert( job, "" );
|
||||
mProviderJobs[ job ] = p;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::slotNewStuffJobData( TDEIO::Job *job, const TQByteArray &data )
|
||||
{
|
||||
if ( data.isEmpty() ) return;
|
||||
|
||||
kdDebug(5850) << "Engine:slotNewStuffJobData()" << endl;
|
||||
|
||||
TQCString str( data, data.size() + 1 );
|
||||
|
||||
mNewStuffJobData[ job ].append( TQString::fromUtf8( str ) );
|
||||
}
|
||||
|
||||
void Engine::slotNewStuffJobResult( TDEIO::Job *job )
|
||||
{
|
||||
if ( job->error() ) {
|
||||
kdDebug(5850) << "Error downloading new stuff descriptions." << endl;
|
||||
job->showErrorDialog( mParentWidget );
|
||||
} else {
|
||||
TQString knewstuffDoc = mNewStuffJobData[ job ];
|
||||
|
||||
kdDebug(5850) << "---START---" << endl << knewstuffDoc << "---END---" << endl;
|
||||
|
||||
mDownloadDialog->addProvider( mProviderJobs[ job ] );
|
||||
|
||||
TQDomDocument doc;
|
||||
if ( !doc.setContent( knewstuffDoc ) ) {
|
||||
kdDebug(5850) << "Error parsing knewstuff.xml." << endl;
|
||||
return;
|
||||
} else {
|
||||
TQDomElement knewstuff = doc.documentElement();
|
||||
|
||||
if ( knewstuff.isNull() ) {
|
||||
kdDebug(5850) << "No document in knewstuffproviders.xml." << endl;
|
||||
} else {
|
||||
TQDomNode p;
|
||||
for ( p = knewstuff.firstChild(); !p.isNull(); p = p.nextSibling() ) {
|
||||
TQDomElement stuff = p.toElement();
|
||||
if ( stuff.tagName() != "stuff" ) continue;
|
||||
if ( stuff.attribute("type", mType) != mType ) continue;
|
||||
|
||||
Entry *entry = new Entry( stuff );
|
||||
mNewStuffList.append( entry );
|
||||
|
||||
mDownloadDialog->show();
|
||||
|
||||
mDownloadDialog->addEntry( entry );
|
||||
|
||||
kdDebug(5850) << "KNEWSTUFF: " << entry->name() << endl;
|
||||
|
||||
kdDebug(5850) << " SUMMARY: " << entry->summary() << endl;
|
||||
kdDebug(5850) << " VERSION: " << entry->version() << endl;
|
||||
kdDebug(5850) << " RELEASEDATE: " << entry->releaseDate().toString() << endl;
|
||||
kdDebug(5850) << " RATING: " << entry->rating() << endl;
|
||||
|
||||
kdDebug(5850) << " LANGS: " << entry->langs().join(", ") << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mNewStuffJobData.remove( job );
|
||||
mProviderJobs.remove( job );
|
||||
|
||||
if ( mNewStuffJobData.count() == 0 ) {
|
||||
mDownloadDialog->show();
|
||||
mDownloadDialog->raise();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::download( Entry *entry )
|
||||
{
|
||||
kdDebug(5850) << "Engine::download(entry)" << endl;
|
||||
|
||||
KURL source = entry->payload();
|
||||
mDownloadDestination = mNewStuff->downloadDestination( entry );
|
||||
|
||||
if ( mDownloadDestination.isEmpty() ) {
|
||||
kdDebug(5850) << "Empty downloadDestination. Cancelling download." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
KURL destination = KURL( mDownloadDestination );
|
||||
|
||||
kdDebug(5850) << " SOURCE: " << source.url() << endl;
|
||||
kdDebug(5850) << " DESTINATION: " << destination.url() << endl;
|
||||
|
||||
TDEIO::FileCopyJob *job = TDEIO::file_copy( source, destination, -1, true );
|
||||
connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||||
TQT_SLOT( slotDownloadJobResult( TDEIO::Job * ) ) );
|
||||
}
|
||||
|
||||
void Engine::slotDownloadJobResult( TDEIO::Job *job )
|
||||
{
|
||||
if ( job->error() ) {
|
||||
kdDebug(5850) << "Error downloading new stuff payload." << endl;
|
||||
job->showErrorDialog( mParentWidget );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mNewStuff->install( mDownloadDestination ) ) {
|
||||
if ( !mIgnoreInstallResult ) {
|
||||
KMessageBox::information( mParentWidget,
|
||||
i18n("Successfully installed hot new stuff.") );
|
||||
}
|
||||
} else
|
||||
if ( !mIgnoreInstallResult ){
|
||||
KMessageBox::error( mParentWidget,
|
||||
i18n("Failed to install hot new stuff.") );
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::upload(const TQString &fileName, const TQString &previewName )
|
||||
{
|
||||
mUploadFile = fileName;
|
||||
mPreviewFile = previewName;
|
||||
|
||||
connect( mProviderLoader,
|
||||
TQT_SIGNAL( providersLoaded( Provider::List * ) ),
|
||||
TQT_SLOT( selectUploadProvider( Provider::List * ) ) );
|
||||
mProviderLoader->load( mType );
|
||||
}
|
||||
|
||||
void Engine::selectUploadProvider( Provider::List *providers )
|
||||
{
|
||||
kdDebug(5850) << "Engine:selectUploadProvider()" << endl;
|
||||
|
||||
mProviderLoader->disconnect();
|
||||
|
||||
if ( !mProviderDialog ) {
|
||||
mProviderDialog = new ProviderDialog( this, mParentWidget );
|
||||
}
|
||||
|
||||
mProviderDialog->clear();
|
||||
|
||||
mProviderDialog->show();
|
||||
mProviderDialog->raise();
|
||||
|
||||
for( Provider *p = providers->first(); p; p = providers->next() ) {
|
||||
mProviderDialog->addProvider( p );
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::requestMetaInformation( Provider *provider )
|
||||
{
|
||||
mUploadProvider = provider;
|
||||
|
||||
if ( !mUploadDialog ) {
|
||||
mUploadDialog = new UploadDialog( this, mParentWidget );
|
||||
}
|
||||
mUploadDialog->setPreviewFile( mPreviewFile );
|
||||
mUploadDialog->show();
|
||||
mUploadDialog->raise();
|
||||
}
|
||||
|
||||
void Engine::upload( Entry *entry )
|
||||
{
|
||||
if ( mUploadFile.isNull()) {
|
||||
mUploadFile = entry->fullName();
|
||||
mUploadFile = locateLocal( "data", TQString(kapp->instanceName()) + "/upload/" + mUploadFile );
|
||||
|
||||
if ( !mNewStuff->createUploadFile( mUploadFile ) ) {
|
||||
KMessageBox::error( mParentWidget, i18n("Unable to create file to upload.") );
|
||||
emit uploadFinished( false );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TQString lang = entry->langs().first();
|
||||
TQFileInfo fi( mUploadFile );
|
||||
entry->setPayload( KURL::fromPathOrURL( fi.fileName() ), lang );
|
||||
|
||||
if ( !createMetaFile( entry ) ) {
|
||||
emit uploadFinished( false );
|
||||
return;
|
||||
}
|
||||
|
||||
TQString text = i18n("The files to be uploaded have been created at:\n");
|
||||
text.append( i18n("Data file: %1\n").arg( mUploadFile) );
|
||||
if (!mPreviewFile.isEmpty()) {
|
||||
text.append( i18n("Preview image: %1\n").arg( mPreviewFile) );
|
||||
}
|
||||
text.append( i18n("Content information: %1\n").arg( mUploadMetaFile) );
|
||||
text.append( i18n("Those files can now be uploaded.\n") );
|
||||
text.append( i18n("Beware that any people might have access to them at any time.") );
|
||||
|
||||
TQString caption = i18n("Upload Files");
|
||||
|
||||
if ( mUploadProvider->noUpload() ) {
|
||||
KURL noUploadUrl = mUploadProvider->noUploadUrl();
|
||||
if ( noUploadUrl.isEmpty() ) {
|
||||
text.append( i18n("Please upload the files manually.") );
|
||||
KMessageBox::information( mParentWidget, text, caption );
|
||||
} else {
|
||||
int result = KMessageBox::questionYesNo( mParentWidget, text, caption,
|
||||
i18n("Upload Info"),
|
||||
KStdGuiItem::close() );
|
||||
if ( result == KMessageBox::Yes ) {
|
||||
kapp->invokeBrowser( noUploadUrl.url() );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int result = KMessageBox::questionYesNo( mParentWidget, text, caption,
|
||||
i18n("&Upload"), KStdGuiItem::cancel() );
|
||||
if ( result == KMessageBox::Yes ) {
|
||||
KURL destination = mUploadProvider->uploadUrl();
|
||||
destination.setFileName( fi.fileName() );
|
||||
|
||||
TDEIO::FileCopyJob *job = TDEIO::file_copy( KURL::fromPathOrURL( mUploadFile ), destination );
|
||||
connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||||
TQT_SLOT( slotUploadPayloadJobResult( TDEIO::Job * ) ) );
|
||||
} else {
|
||||
emit uploadFinished( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Engine::createMetaFile( Entry *entry )
|
||||
{
|
||||
TQDomDocument doc("knewstuff");
|
||||
doc.appendChild( doc.createProcessingInstruction(
|
||||
"xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
|
||||
TQDomElement de = doc.createElement("knewstuff");
|
||||
doc.appendChild( de );
|
||||
|
||||
entry->setType(type());
|
||||
de.appendChild( entry->createDomElement( doc, de ) );
|
||||
|
||||
kdDebug(5850) << "--DOM START--" << endl << doc.toString()
|
||||
<< "--DOM_END--" << endl;
|
||||
|
||||
if ( mUploadMetaFile.isNull() ) {
|
||||
mUploadMetaFile = entry->fullName() + ".meta";
|
||||
mUploadMetaFile = locateLocal( "data", TQString(kapp->instanceName()) + "/upload/" + mUploadMetaFile );
|
||||
}
|
||||
|
||||
TQFile f( mUploadMetaFile );
|
||||
if ( !f.open( IO_WriteOnly ) ) {
|
||||
mUploadMetaFile = TQString();
|
||||
return false;
|
||||
}
|
||||
|
||||
TQTextStream ts( &f );
|
||||
ts.setEncoding( TQTextStream::UnicodeUTF8 );
|
||||
ts << doc.toString();
|
||||
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Engine::slotUploadPayloadJobResult( TDEIO::Job *job )
|
||||
{
|
||||
if ( job->error() ) {
|
||||
kdDebug(5850) << "Error uploading new stuff payload." << endl;
|
||||
job->showErrorDialog( mParentWidget );
|
||||
emit uploadFinished( false );
|
||||
return;
|
||||
}
|
||||
|
||||
if (mPreviewFile.isEmpty()) {
|
||||
slotUploadPreviewJobResult(job);
|
||||
return;
|
||||
}
|
||||
|
||||
TQFileInfo fi( mPreviewFile );
|
||||
|
||||
KURL previewDestination = mUploadProvider->uploadUrl();
|
||||
previewDestination.setFileName( fi.fileName() );
|
||||
|
||||
TDEIO::FileCopyJob *newJob = TDEIO::file_copy( KURL::fromPathOrURL( mPreviewFile ), previewDestination );
|
||||
connect( newJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||||
TQT_SLOT( slotUploadPreviewJobResult( TDEIO::Job * ) ) );
|
||||
}
|
||||
|
||||
void Engine::slotUploadPreviewJobResult( TDEIO::Job *job )
|
||||
{
|
||||
if ( job->error() ) {
|
||||
kdDebug(5850) << "Error uploading new stuff preview." << endl;
|
||||
job->showErrorDialog( mParentWidget );
|
||||
emit uploadFinished( true );
|
||||
return;
|
||||
}
|
||||
|
||||
TQFileInfo fi( mUploadMetaFile );
|
||||
|
||||
KURL metaDestination = mUploadProvider->uploadUrl();
|
||||
metaDestination.setFileName( fi.fileName() );
|
||||
|
||||
TDEIO::FileCopyJob *newJob = TDEIO::file_copy( KURL::fromPathOrURL( mUploadMetaFile ), metaDestination );
|
||||
connect( newJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||||
TQT_SLOT( slotUploadMetaJobResult( TDEIO::Job * ) ) );
|
||||
}
|
||||
|
||||
void Engine::slotUploadMetaJobResult( TDEIO::Job *job )
|
||||
{
|
||||
mUploadMetaFile = TQString();
|
||||
if ( job->error() ) {
|
||||
kdDebug(5850) << "Error uploading new stuff metadata." << endl;
|
||||
job->showErrorDialog( mParentWidget );
|
||||
emit uploadFinished( false );
|
||||
return;
|
||||
}
|
||||
|
||||
KMessageBox::information( mParentWidget,
|
||||
i18n("Successfully uploaded new stuff.") );
|
||||
emit uploadFinished( true );
|
||||
}
|
||||
|
||||
void Engine::ignoreInstallResult(bool ignore)
|
||||
{
|
||||
mIgnoreInstallResult = ignore;
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_ENGINE_H
|
||||
#define KNEWSTUFF_ENGINE_H
|
||||
|
||||
#include <tqmap.h>
|
||||
#include <tqobject.h>
|
||||
#include <tqstring.h>
|
||||
|
||||
#include "entry.h"
|
||||
#include "provider.h"
|
||||
|
||||
namespace TDEIO { class Job; }
|
||||
|
||||
class KNewStuff;
|
||||
|
||||
namespace KNS {
|
||||
|
||||
class DownloadDialog;
|
||||
class UploadDialog;
|
||||
class ProviderDialog;
|
||||
|
||||
/**
|
||||
* @short Central class combining all possible KNewStuff operations.
|
||||
*
|
||||
* In most cases, Engine objects are built and used internally.
|
||||
* Using this class explicitely does however give fine-grained control about the
|
||||
* upload and download operations.
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class Engine : public TQObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param newStuff a KNewStuff object
|
||||
@param type the Hotstuff data type such as "korganizer/calendar"
|
||||
@param parentWidget the parent window
|
||||
*/
|
||||
Engine( KNewStuff *newStuff, const TQString &type, TQWidget *parentWidget = 0 );
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param newStuff a KNewStuff object
|
||||
@param type the Hotstuff data type such as "korganizer/calendar"
|
||||
@param providerList the URL of the provider list
|
||||
@param parentWidget the parent window
|
||||
*/
|
||||
Engine( KNewStuff *newStuff, const TQString &type, const TQString &providerList, TQWidget *parentWidget = 0 );
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~Engine();
|
||||
|
||||
/**
|
||||
Returns the previously set data type.
|
||||
|
||||
@return the Hotstuff data type
|
||||
*/
|
||||
TQString type() const { return mType; }
|
||||
|
||||
/**
|
||||
Returns the previously set parent widget.
|
||||
|
||||
@return parent widget
|
||||
*/
|
||||
TQWidget *parentWidget() const { return mParentWidget; }
|
||||
|
||||
/**
|
||||
Initiates the download process, retrieving provider lists and invoking
|
||||
the download dialog.
|
||||
*/
|
||||
void download();
|
||||
|
||||
/**
|
||||
Initiates the upload process, invoking the provider selection dialog
|
||||
and the file upload dialog.
|
||||
|
||||
@param fileName name of the payload data file
|
||||
@param previewName name of the preview image file
|
||||
*/
|
||||
void upload( const TQString &fileName = TQString(), const TQString &previewName = TQString() );
|
||||
|
||||
/**
|
||||
Downloads the specified data file.
|
||||
|
||||
@param entry the Hotstuff data object to be downloaded
|
||||
*/
|
||||
void download( Entry *entry );
|
||||
|
||||
/**
|
||||
Asynchronous lookup of provider information such as upload and
|
||||
download locations, icon etc.
|
||||
|
||||
@param provider the Hotstuff provider to request information from
|
||||
*/
|
||||
void requestMetaInformation( Provider *provider );
|
||||
|
||||
/**
|
||||
Uploads the specified data file to the provider-dependent location.
|
||||
|
||||
@param entry the Hotstuff data object to be uploaded
|
||||
*/
|
||||
void upload( Entry *entry );
|
||||
|
||||
/**
|
||||
Ignores the return value of the install method. Used internally to
|
||||
avoid showing of the success/failure dialog when installation is done
|
||||
in another place, like in @ref KNewStuffSecure
|
||||
*/
|
||||
void ignoreInstallResult(bool ignore);
|
||||
|
||||
signals:
|
||||
/** Emitted when the upload has finished.
|
||||
@param result indicates the success/failure of the upload
|
||||
*/
|
||||
void uploadFinished( bool result );
|
||||
protected slots:
|
||||
void getMetaInformation( Provider::List *providers );
|
||||
void selectUploadProvider( Provider::List *providers );
|
||||
|
||||
void slotNewStuffJobData( TDEIO::Job *job, const TQByteArray &data );
|
||||
void slotNewStuffJobResult( TDEIO::Job *job );
|
||||
|
||||
void slotDownloadJobResult( TDEIO::Job *job );
|
||||
|
||||
void slotUploadPayloadJobResult( TDEIO::Job *job );
|
||||
void slotUploadPreviewJobResult (TDEIO::Job *job );
|
||||
void slotUploadMetaJobResult( TDEIO::Job *job );
|
||||
|
||||
protected:
|
||||
bool createMetaFile( Entry * );
|
||||
|
||||
private:
|
||||
TQWidget *mParentWidget;
|
||||
|
||||
ProviderLoader *mProviderLoader;
|
||||
|
||||
TQMap<TDEIO::Job *,TQString> mNewStuffJobData;
|
||||
TQMap<TDEIO::Job *,Provider *> mProviderJobs;
|
||||
|
||||
TQPtrList<Entry> mNewStuffList;
|
||||
|
||||
DownloadDialog *mDownloadDialog;
|
||||
UploadDialog *mUploadDialog;
|
||||
ProviderDialog *mProviderDialog;
|
||||
|
||||
TQString mDownloadDestination;
|
||||
|
||||
Provider *mUploadProvider;
|
||||
|
||||
TQString mUploadMetaFile;
|
||||
TQString mUploadFile;
|
||||
TQString mPreviewFile;
|
||||
TQString mProviderList;
|
||||
|
||||
KNewStuff *mNewStuff;
|
||||
|
||||
TQString mType;
|
||||
|
||||
bool mIgnoreInstallResult;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,294 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "entry.h"
|
||||
|
||||
#include <tdeglobal.h>
|
||||
#include <tdelocale.h>
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
Entry::Entry() :
|
||||
mRelease( 0 ), mReleaseDate( TQDate::currentDate() ), mRating( 0 ),
|
||||
mDownloads( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
Entry::Entry( const TQDomElement &e )
|
||||
{
|
||||
parseDomElement( e );
|
||||
}
|
||||
|
||||
Entry::~Entry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Entry::setName( const TQString &name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
TQString Entry::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setType( const TQString &type )
|
||||
{
|
||||
mType = type;
|
||||
}
|
||||
|
||||
TQString Entry::type() const
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setAuthor( const TQString &author )
|
||||
{
|
||||
mAuthor = author;
|
||||
}
|
||||
|
||||
TQString Entry::author() const
|
||||
{
|
||||
return mAuthor;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setLicence( const TQString &license )
|
||||
{
|
||||
mLicence = license;
|
||||
}
|
||||
|
||||
TQString Entry::license() const
|
||||
{
|
||||
return mLicence;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setSummary( const TQString &text, const TQString &lang )
|
||||
{
|
||||
mSummaryMap.insert( lang, text );
|
||||
|
||||
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||||
}
|
||||
|
||||
TQString Entry::summary( const TQString &lang ) const
|
||||
{
|
||||
if ( mSummaryMap.isEmpty() ) return TQString();
|
||||
|
||||
if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
|
||||
else {
|
||||
TQStringList langs = TDEGlobal::locale()->languageList();
|
||||
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||||
if( !mSummaryMap[ *it ].isEmpty() ) return mSummaryMap[ *it ];
|
||||
}
|
||||
if ( !mSummaryMap[ TQString() ].isEmpty() ) return mSummaryMap[ TQString() ];
|
||||
else return *(mSummaryMap.begin());
|
||||
}
|
||||
|
||||
|
||||
void Entry::setVersion( const TQString &version )
|
||||
{
|
||||
mVersion = version;
|
||||
}
|
||||
|
||||
TQString Entry::version() const
|
||||
{
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setRelease( int release )
|
||||
{
|
||||
mRelease = release;
|
||||
}
|
||||
|
||||
int Entry::release() const
|
||||
{
|
||||
return mRelease;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setReleaseDate( const TQDate &d )
|
||||
{
|
||||
mReleaseDate = d;
|
||||
}
|
||||
|
||||
TQDate Entry::releaseDate() const
|
||||
{
|
||||
return mReleaseDate;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setPayload( const KURL &url, const TQString &lang )
|
||||
{
|
||||
mPayloadMap.insert( lang, url );
|
||||
|
||||
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||||
}
|
||||
|
||||
KURL Entry::payload( const TQString &lang ) const
|
||||
{
|
||||
KURL payload = mPayloadMap[ lang ];
|
||||
if ( payload.isEmpty() ) {
|
||||
TQStringList langs = TDEGlobal::locale()->languageList();
|
||||
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||||
if( !mPayloadMap[ *it ].isEmpty() ) return mPayloadMap[ *it ];
|
||||
}
|
||||
if ( payload.isEmpty() ) payload = mPayloadMap [ TQString() ];
|
||||
if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
|
||||
payload = *(mPayloadMap.begin());
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setPreview( const KURL &url, const TQString &lang )
|
||||
{
|
||||
mPreviewMap.insert( lang, url );
|
||||
|
||||
if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
|
||||
}
|
||||
|
||||
KURL Entry::preview( const TQString &lang ) const
|
||||
{
|
||||
KURL preview = mPreviewMap[ lang ];
|
||||
if ( preview.isEmpty() ) {
|
||||
TQStringList langs = TDEGlobal::locale()->languageList();
|
||||
for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
|
||||
if( !mPreviewMap[ *it ].isEmpty() ) return mPreviewMap[ *it ];
|
||||
}
|
||||
if ( preview.isEmpty() ) preview = mPreviewMap [ TQString() ];
|
||||
if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
|
||||
preview = *(mPreviewMap.begin());
|
||||
}
|
||||
return preview;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setRating( int rating )
|
||||
{
|
||||
mRating = rating;
|
||||
}
|
||||
|
||||
int Entry::rating()
|
||||
{
|
||||
return mRating;
|
||||
}
|
||||
|
||||
|
||||
void Entry::setDownloads( int downloads )
|
||||
{
|
||||
mDownloads = downloads;
|
||||
}
|
||||
|
||||
int Entry::downloads()
|
||||
{
|
||||
return mDownloads;
|
||||
}
|
||||
|
||||
TQString Entry::fullName()
|
||||
{
|
||||
return name() + "-" + version() + "-" + TQString::number( release() );
|
||||
}
|
||||
|
||||
TQStringList Entry::langs()
|
||||
{
|
||||
return mLangs;
|
||||
}
|
||||
|
||||
void Entry::parseDomElement( const TQDomElement &element )
|
||||
{
|
||||
if ( element.tagName() != "stuff" ) return;
|
||||
mType = element.attribute("type");
|
||||
|
||||
TQDomNode n;
|
||||
for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||||
TQDomElement e = n.toElement();
|
||||
if ( e.tagName() == "name" ) setName( e.text().stripWhiteSpace() );
|
||||
if ( e.tagName() == "author" ) setAuthor( e.text().stripWhiteSpace() );
|
||||
if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
|
||||
if ( e.tagName() == "summary" ) {
|
||||
TQString lang = e.attribute( "lang" );
|
||||
setSummary( e.text().stripWhiteSpace(), lang );
|
||||
}
|
||||
if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
|
||||
if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
|
||||
if ( e.tagName() == "releasedate" ) {
|
||||
TQDate date = TQDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate );
|
||||
setReleaseDate( date );
|
||||
}
|
||||
if ( e.tagName() == "preview" ) {
|
||||
TQString lang = e.attribute( "lang" );
|
||||
setPreview( KURL( e.text().stripWhiteSpace() ), lang );
|
||||
}
|
||||
if ( e.tagName() == "payload" ) {
|
||||
TQString lang = e.attribute( "lang" );
|
||||
setPayload( KURL( e.text().stripWhiteSpace() ), lang );
|
||||
}
|
||||
if ( e.tagName() == "rating" ) setRating( e.text().toInt() );
|
||||
if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
|
||||
}
|
||||
}
|
||||
|
||||
TQDomElement Entry::createDomElement( TQDomDocument &doc,
|
||||
TQDomElement &parent )
|
||||
{
|
||||
TQDomElement entry = doc.createElement( "stuff" );
|
||||
entry.setAttribute("type", mType);
|
||||
parent.appendChild( entry );
|
||||
|
||||
addElement( doc, entry, "name", name() );
|
||||
addElement( doc, entry, "author", author() );
|
||||
addElement( doc, entry, "licence", license() );
|
||||
addElement( doc, entry, "version", version() );
|
||||
addElement( doc, entry, "release", TQString::number( release() ) );
|
||||
addElement( doc, entry, "rating", TQString::number( rating() ) );
|
||||
addElement( doc, entry, "downloads", TQString::number( downloads() ) );
|
||||
|
||||
addElement( doc, entry, "releasedate",
|
||||
releaseDate().toString( Qt::ISODate ) );
|
||||
|
||||
TQStringList ls = langs();
|
||||
TQStringList::ConstIterator it;
|
||||
for( it = ls.begin(); it != ls.end(); ++it ) {
|
||||
TQDomElement e = addElement( doc, entry, "summary", summary( *it ) );
|
||||
e.setAttribute( "lang", *it );
|
||||
e = addElement( doc, entry, "preview", preview( *it ).url() );
|
||||
e.setAttribute( "lang", *it );
|
||||
e = addElement( doc, entry, "payload", payload( *it ).url() );
|
||||
e.setAttribute( "lang", *it );
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
TQDomElement Entry::addElement( TQDomDocument &doc, TQDomElement &parent,
|
||||
const TQString &tag, const TQString &value )
|
||||
{
|
||||
TQDomElement n = doc.createElement( tag );
|
||||
n.appendChild( doc.createTextNode( value ) );
|
||||
parent.appendChild( n );
|
||||
|
||||
return n;
|
||||
}
|
@ -1,257 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_ENTRY_H
|
||||
#define KNEWSTUFF_ENTRY_H
|
||||
|
||||
#include <tqdatetime.h>
|
||||
#include <tqdom.h>
|
||||
#include <tqmap.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqstringlist.h>
|
||||
|
||||
#include <kurl.h>
|
||||
|
||||
namespace KNS {
|
||||
|
||||
/**
|
||||
* @short KNewStuff data entry container.
|
||||
*
|
||||
* This class provides accessor methods to the data objects
|
||||
* as used by KNewStuff.
|
||||
* It should probably not be used directly by the application.
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class KDE_EXPORT Entry
|
||||
{
|
||||
public:
|
||||
Entry();
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Entry( const TQDomElement & );
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Entry();
|
||||
|
||||
/**
|
||||
* Sets the (unique) name for this data object.
|
||||
*/
|
||||
void setName( const TQString & );
|
||||
|
||||
/**
|
||||
* Retrieve the name of the data object.
|
||||
*
|
||||
* @return object name
|
||||
*/
|
||||
TQString name() const;
|
||||
|
||||
/**
|
||||
* Sets the application type, e.g. 'kdesktop/wallpaper'.
|
||||
*/
|
||||
void setType( const TQString & );
|
||||
|
||||
/**
|
||||
* Retrieve the type of the data object.
|
||||
*
|
||||
* @return object type
|
||||
*/
|
||||
TQString type() const;
|
||||
|
||||
/**
|
||||
* Sets the full name of the object's author.
|
||||
*/
|
||||
void setAuthor( const TQString & );
|
||||
|
||||
/**
|
||||
* Retrieve the author's name of the object.
|
||||
*
|
||||
* @return object author
|
||||
*/
|
||||
TQString author() const;
|
||||
|
||||
/**
|
||||
* Sets the license (abbreviation) applicable to the object.
|
||||
*/
|
||||
void setLicence( const TQString & );
|
||||
|
||||
/**
|
||||
* Retrieve the license name of the object.
|
||||
*
|
||||
* @return object license
|
||||
*/
|
||||
TQString license() const;
|
||||
|
||||
/**
|
||||
* Sets a short description on what the object is all about.
|
||||
*/
|
||||
void setSummary( const TQString &, const TQString &lang = TQString() );
|
||||
|
||||
/**
|
||||
* Retrieve a short description about the object.
|
||||
*
|
||||
* @param lang preferred language, or TQString() for KDE default
|
||||
* @return object description
|
||||
*/
|
||||
TQString summary( const TQString &lang = TQString() ) const;
|
||||
|
||||
/**
|
||||
* Sets the version number.
|
||||
*/
|
||||
void setVersion( const TQString & );
|
||||
|
||||
/**
|
||||
* Retrieve the version string of the object.
|
||||
*
|
||||
* @return object version
|
||||
*/
|
||||
TQString version() const;
|
||||
|
||||
/**
|
||||
* Sets the release number, which is increased for feature-equal objects
|
||||
* with the same version number, but slightly updated contents.
|
||||
*/
|
||||
void setRelease( int );
|
||||
|
||||
/**
|
||||
* Retrieve the release number of the object
|
||||
*
|
||||
* @return object release
|
||||
*/
|
||||
int release() const;
|
||||
|
||||
/**
|
||||
* Sets the release date.
|
||||
*/
|
||||
void setReleaseDate( const TQDate & );
|
||||
|
||||
/**
|
||||
* Retrieve the date of the object's publication.
|
||||
*
|
||||
* @return object release date
|
||||
*/
|
||||
TQDate releaseDate() const;
|
||||
|
||||
/**
|
||||
* Sets the object's file.
|
||||
*/
|
||||
void setPayload( const KURL &, const TQString &lang = TQString() );
|
||||
|
||||
/**
|
||||
* Retrieve the file name of the object.
|
||||
*
|
||||
* @param lang preferred language, or TQString() for KDE default
|
||||
* @return object filename
|
||||
*/
|
||||
KURL payload( const TQString &lang = TQString() ) const;
|
||||
|
||||
/**
|
||||
* Sets the object's preview file, if available. This should be a
|
||||
* picture file.
|
||||
*/
|
||||
void setPreview( const KURL &, const TQString &lang = TQString() );
|
||||
|
||||
/**
|
||||
* Retrieve the file name of an image containing a preview of the object.
|
||||
*
|
||||
* @param lang preferred language, or TQString() for KDE default
|
||||
* @return object preview filename
|
||||
*/
|
||||
KURL preview( const TQString &lang = TQString() ) const;
|
||||
|
||||
/**
|
||||
* Sets the rating between 0 (worst) and 10 (best).
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
void setRating( int );
|
||||
|
||||
/**
|
||||
* Retrieve the rating for the object, which has been determined by its
|
||||
* users and thus might change over time.
|
||||
*
|
||||
* @return object rating
|
||||
*/
|
||||
int rating();
|
||||
|
||||
/**
|
||||
* Sets the number of downloads.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
void setDownloads( int );
|
||||
|
||||
/**
|
||||
* Retrieve the download count for the object, which has been determined
|
||||
* by its hosting sites and thus might change over time.
|
||||
*
|
||||
* @return object download count
|
||||
*/
|
||||
int downloads();
|
||||
|
||||
/**
|
||||
* Return the full name for the meta information. It is constructed as
|
||||
* name-version-release.
|
||||
*/
|
||||
TQString fullName();
|
||||
|
||||
/**
|
||||
* Return the list of languages this object supports.
|
||||
*/
|
||||
TQStringList langs();
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void parseDomElement( const TQDomElement & );
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
TQDomElement createDomElement( TQDomDocument &, TQDomElement &parent );
|
||||
|
||||
protected:
|
||||
TQDomElement addElement( TQDomDocument &doc, TQDomElement &parent,
|
||||
const TQString &tag, const TQString &value );
|
||||
|
||||
private:
|
||||
TQString mName;
|
||||
TQString mType;
|
||||
TQString mAuthor;
|
||||
TQString mLicence;
|
||||
TQMap<TQString,TQString> mSummaryMap;
|
||||
TQString mVersion;
|
||||
int mRelease;
|
||||
TQDate mReleaseDate;
|
||||
TQMap<TQString,KURL> mPayloadMap;
|
||||
TQMap<TQString,KURL> mPreviewMap;
|
||||
int mRating;
|
||||
int mDownloads;
|
||||
|
||||
TQStringList mLangs;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tdeaction.h>
|
||||
#include <tdeapplication.h>
|
||||
#include <kdebug.h>
|
||||
#include <tdelocale.h>
|
||||
#include <kstandarddirs.h>
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
#include "knewstuff.h"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
TDEAction* KNS::standardAction(const TQString& what,
|
||||
const TQObject *recvr,
|
||||
const char *slot, TDEActionCollection* parent,
|
||||
const char *name)
|
||||
{
|
||||
return new TDEAction(i18n("Download New %1").arg(what), "knewstuff",
|
||||
0, recvr, slot, parent, name);
|
||||
}
|
||||
|
||||
KNewStuff::KNewStuff( const TQString &type, TQWidget *parentWidget )
|
||||
{
|
||||
mEngine = new Engine( this, type, parentWidget );
|
||||
}
|
||||
|
||||
KNewStuff::KNewStuff( const TQString &type, const TQString &providerList, TQWidget *parentWidget )
|
||||
{
|
||||
mEngine = new Engine( this, type, providerList, parentWidget );
|
||||
}
|
||||
|
||||
TQString KNewStuff::type() const
|
||||
{
|
||||
return mEngine->type();
|
||||
}
|
||||
|
||||
TQWidget *KNewStuff::parentWidget() const
|
||||
{
|
||||
return mEngine->parentWidget();
|
||||
}
|
||||
|
||||
KNewStuff::~KNewStuff()
|
||||
{
|
||||
delete mEngine;
|
||||
}
|
||||
|
||||
void KNewStuff::download()
|
||||
{
|
||||
mEngine->download();
|
||||
}
|
||||
|
||||
TQString KNewStuff::downloadDestination( Entry * )
|
||||
{
|
||||
return TDEGlobal::dirs()->saveLocation( "tmp" ) +
|
||||
TDEApplication::randomString( 10 );
|
||||
}
|
||||
|
||||
void KNewStuff::upload()
|
||||
{
|
||||
mEngine->upload();
|
||||
}
|
||||
|
||||
void KNewStuff::upload( const TQString &fileName, const TQString previewName )
|
||||
{
|
||||
mEngine->upload(fileName, previewName);
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_H
|
||||
#define KNEWSTUFF_H
|
||||
|
||||
#include <tqstring.h>
|
||||
|
||||
#include <kdemacros.h>
|
||||
|
||||
class TQObject;
|
||||
class TQWidget;
|
||||
class TDEAction;
|
||||
class TDEActionCollection;
|
||||
|
||||
namespace KNS {
|
||||
class Engine;
|
||||
class Entry;
|
||||
|
||||
TDEAction* standardAction(const TQString& what,
|
||||
const TQObject *recvr,
|
||||
const char *slot,
|
||||
TDEActionCollection* parent,
|
||||
const char *name = 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @short This class provides the functionality to download and upload "new stuff".
|
||||
*
|
||||
* Applications have to subclass KNewStuff, implement the pure virtual functions
|
||||
* and link to against libknewstuff.
|
||||
*
|
||||
* By calling download() the download process is started which means that a list
|
||||
* of "providers" is fetched from a "master server", information about new stuff
|
||||
* is collected from the providers and presented to the user. Selected entries
|
||||
* get downloaded and installed to the application. The required functions to
|
||||
* install new stuff are provided by implementing install(). The location where
|
||||
* the downloaded files are stored can be customized by reimplementing
|
||||
* downloadDestination().
|
||||
*
|
||||
* By calling upload() the upload process is started which means the user has to
|
||||
* select a provider from the list fetched from the master server and to put in
|
||||
* information about the entry to be uploaded. Then the file to be uploaded is
|
||||
* fetched from the application by calling createUploadFile() and transfered to
|
||||
* the upload destination specified in the provider list.
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
class KDE_EXPORT KNewStuff
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param type type of data to be handled, should be something like
|
||||
korganizer/calendar, kword/template, kdesktop/wallpaper
|
||||
@param parentWidget parent widget of dialogs opened by the KNewStuff
|
||||
engine
|
||||
*/
|
||||
KNewStuff( const TQString &type, TQWidget *parentWidget = 0 );
|
||||
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param type type of data to be handled, should be something like
|
||||
korganizer/calendar, kword/template, kdesktop/wallpaper
|
||||
@param providerList the URL of the provider list
|
||||
@param parentWidget parent widget of dialogs opened by the KNewStuff
|
||||
engine
|
||||
*/
|
||||
KNewStuff( const TQString &type, const TQString &providerList, TQWidget *parentWidget = 0 );
|
||||
virtual ~KNewStuff();
|
||||
|
||||
/**
|
||||
Return type of data.
|
||||
*/
|
||||
TQString type() const;
|
||||
|
||||
/**
|
||||
Return parent widget.
|
||||
*/
|
||||
TQWidget *parentWidget() const;
|
||||
|
||||
/**
|
||||
Start download process.
|
||||
*/
|
||||
void download();
|
||||
|
||||
/**
|
||||
Start upload process.
|
||||
*/
|
||||
void upload();
|
||||
|
||||
/**
|
||||
Upload with pre-defined files.
|
||||
*/
|
||||
void upload( const TQString &fileName, const TQString previewName );
|
||||
|
||||
/**
|
||||
Install file to application. The given fileName points to the file
|
||||
downloaded by the KNewStuff engine. This is a temporary file by default.
|
||||
The application can do whatever is needed to handle the information
|
||||
contained in the file.
|
||||
|
||||
The function returns true, when the installation
|
||||
was successful and false if were errors.
|
||||
|
||||
@param fileName name of downloaded file
|
||||
*/
|
||||
virtual bool install( const TQString &fileName ) = 0;
|
||||
/**
|
||||
Create a file to be uploaded to a "new stuff provider" and return the
|
||||
filename. The format of the file is application specific. The only
|
||||
constraint is that the corresponding install() implementation is able to
|
||||
use the file.
|
||||
|
||||
@param fileName name of the file to be written
|
||||
@return @c true on success, @c false on error.
|
||||
*/
|
||||
virtual bool createUploadFile( const TQString &fileName ) = 0;
|
||||
|
||||
/**
|
||||
Return a filename which should be used as destination for downloading the
|
||||
specified new stuff entry. Reimplement this function, if you don't want
|
||||
the new stuff to be downloaded to a temporary file.
|
||||
*/
|
||||
virtual TQString downloadDestination( KNS::Entry *entry );
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
Get the pointer to the engine. Needed by subclasses to access the KNS::Engine object.
|
||||
*/
|
||||
KNS::Engine *engine() { return mEngine; }
|
||||
|
||||
|
||||
private:
|
||||
KNS::Engine *mEngine;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
This file is part of KDE.
|
||||
|
||||
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tqfile.h>
|
||||
#include <tqtextstream.h>
|
||||
#include <tqdir.h>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <tdelocale.h>
|
||||
#include <kprocess.h>
|
||||
#include <tdeconfig.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <ktar.h>
|
||||
|
||||
#include "entry.h"
|
||||
|
||||
#include "knewstuffgeneric.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
KNewStuffGeneric::KNewStuffGeneric( const TQString &type, TQWidget *parent )
|
||||
: KNewStuff( type, parent )
|
||||
{
|
||||
mConfig = TDEGlobal::config();
|
||||
}
|
||||
|
||||
KNewStuffGeneric::~KNewStuffGeneric()
|
||||
{
|
||||
}
|
||||
|
||||
bool KNewStuffGeneric::install( const TQString &fileName )
|
||||
{
|
||||
kdDebug(5850) << "KNewStuffGeneric::install(): " << fileName << endl;
|
||||
TQStringList list, list2;
|
||||
|
||||
mConfig->setGroup("KNewStuff");
|
||||
|
||||
TQString uncompress = mConfig->readEntry( "Uncompress" );
|
||||
if ( !uncompress.isEmpty() ) {
|
||||
kdDebug(5850) << "Uncompression method: " << uncompress << endl;
|
||||
KTar tar(fileName, uncompress);
|
||||
tar.open(IO_ReadOnly);
|
||||
const KArchiveDirectory *dir = tar.directory();
|
||||
dir->copyTo(destinationPath(0));
|
||||
tar.close();
|
||||
TQFile::remove(fileName);
|
||||
}
|
||||
|
||||
TQString cmd = mConfig->readEntry( "InstallationCommand" );
|
||||
if ( !cmd.isEmpty() ) {
|
||||
kdDebug(5850) << "InstallationCommand: " << cmd << endl;
|
||||
list = TQStringList::split( " ", cmd );
|
||||
for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
list2 << (*it).replace("%f", fileName);
|
||||
}
|
||||
TDEProcess proc;
|
||||
proc << list2;
|
||||
proc.start( TDEProcess::Block );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KNewStuffGeneric::createUploadFile( const TQString & /*fileName*/ )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TQString KNewStuffGeneric::destinationPath( KNS::Entry *entry )
|
||||
{
|
||||
TQString path, file, target;
|
||||
|
||||
mConfig->setGroup("KNewStuff");
|
||||
|
||||
if( entry ) target = entry->fullName();
|
||||
else target = "/";
|
||||
TQString res = mConfig->readEntry( "StandardResource" );
|
||||
if ( res.isEmpty() )
|
||||
{
|
||||
target = mConfig->readEntry("TargetDir");
|
||||
if ( !target.isEmpty())
|
||||
{
|
||||
res = "data";
|
||||
if ( entry ) target.append("/" + entry->fullName());
|
||||
else target.append("/");
|
||||
}
|
||||
}
|
||||
if ( res.isEmpty() )
|
||||
{
|
||||
path = mConfig->readEntry( "InstallPath" );
|
||||
}
|
||||
if ( res.isEmpty() && path.isEmpty() )
|
||||
{
|
||||
if ( !entry ) return TQString();
|
||||
else return KNewStuff::downloadDestination( entry );
|
||||
}
|
||||
|
||||
if ( !path.isEmpty() )
|
||||
{
|
||||
file = TQDir::home().path() + "/" + path + "/";
|
||||
if ( entry ) file += entry->fullName();
|
||||
}
|
||||
else file = locateLocal( res.utf8() , target );
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
TQString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
|
||||
{
|
||||
TQString file = destinationPath(entry);
|
||||
|
||||
if ( TDEStandardDirs::exists( file ) ) {
|
||||
int result = KMessageBox::warningContinueCancel( parentWidget(),
|
||||
i18n("The file '%1' already exists. Do you want to override it?")
|
||||
.arg( file ),
|
||||
TQString(), i18n("Overwrite") );
|
||||
if ( result == KMessageBox::Cancel ) return TQString();
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
This file is part of KDE.
|
||||
|
||||
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFFGENERIC_H
|
||||
#define KNEWSTUFFGENERIC_H
|
||||
|
||||
#include "knewstuff.h"
|
||||
|
||||
class TDEConfig;
|
||||
|
||||
/**
|
||||
* @short Basic KNewStuff class with predefined actions.
|
||||
*
|
||||
* This class is used for data uploads and installation.
|
||||
* \code
|
||||
* TQString payload, preview;
|
||||
* KNewStuffGeneric *ns = new KNewStuffGeneric("kamikaze/level", this);
|
||||
* ns->upload(payload, preview);
|
||||
* \endcode
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class KDE_EXPORT KNewStuffGeneric : public KNewStuff
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param type a Hotstuff data type such as "korganizer/calendar"
|
||||
@param parent the parent window.
|
||||
*/
|
||||
KNewStuffGeneric( const TQString &type, TQWidget *parent = 0 );
|
||||
~KNewStuffGeneric();
|
||||
|
||||
/**
|
||||
Installs a downloaded file according to the application's configuration.
|
||||
|
||||
@param fileName filename of the donwloaded file
|
||||
@return @c true in case of installation success, @c false otherwise
|
||||
*/
|
||||
bool install( const TQString &fileName );
|
||||
|
||||
/**
|
||||
Creates a file suitable for upload.
|
||||
Note that this method always fails, since using KNewStuffGeneric
|
||||
means that the provided file must already be in a usable format.
|
||||
|
||||
@param fileName the name of the file to upload after its creation
|
||||
@return @c true in case of creation success, @c false otherwise
|
||||
*/
|
||||
bool createUploadFile( const TQString &fileName );
|
||||
|
||||
/**
|
||||
Queries the preferred destination file for a download.
|
||||
|
||||
@param entry a Hotstuff data entry
|
||||
@return destination filename, or 0 to return directory only
|
||||
*/
|
||||
TQString downloadDestination( KNS::Entry *entry );
|
||||
|
||||
private:
|
||||
TQString destinationPath( KNS::Entry *entry );
|
||||
|
||||
TDEConfig *mConfig;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,240 +0,0 @@
|
||||
/***************************************************************************
|
||||
knewstuffsecure.cpp - description
|
||||
-------------------
|
||||
begin : Tue Jun 22 12:19:55 2004
|
||||
copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; version 2 of the License. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
//qt includes
|
||||
#include <tqfileinfo.h>
|
||||
|
||||
//kde includes
|
||||
#include <tdeconfig.h>
|
||||
#include <kdebug.h>
|
||||
#include <tdeglobal.h>
|
||||
#include <tdeio/netaccess.h>
|
||||
#include <tdelocale.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <ktar.h>
|
||||
#include <ktempdir.h>
|
||||
|
||||
//app includes
|
||||
#include "engine.h"
|
||||
#include "knewstuffsecure.h"
|
||||
#include "security.h"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
KNewStuffSecure::KNewStuffSecure(const TQString &type, TQWidget *parentWidget)
|
||||
: KNewStuff(type, parentWidget)
|
||||
{
|
||||
m_tempDir = 0L;
|
||||
connect(engine(), TQT_SIGNAL(uploadFinished(bool)), TQT_SLOT(slotUploadFinished(bool)));
|
||||
}
|
||||
|
||||
|
||||
KNewStuffSecure::~KNewStuffSecure()
|
||||
{
|
||||
removeTempDirectory();
|
||||
}
|
||||
|
||||
bool KNewStuffSecure::install(const TQString &fileName)
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
removeTempDirectory();
|
||||
m_tempDir = new KTempDir();
|
||||
m_tempDir->setAutoDelete(true);
|
||||
KTar tar(fileName, "application/x-gzip");
|
||||
if (tar.open(IO_ReadOnly))
|
||||
{
|
||||
const KArchiveDirectory *directory = tar.directory();
|
||||
directory->copyTo(m_tempDir->name(), true);
|
||||
m_tarName = "";
|
||||
TQStringList entries = directory->entries();
|
||||
for (TQStringList::Iterator it = entries.begin(); it != entries.end(); ++it)
|
||||
{
|
||||
if (*it != "signature" && *it != "md5sum")
|
||||
{
|
||||
m_tarName = *it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tar.close();
|
||||
if (m_tarName.isEmpty())
|
||||
ok = false;
|
||||
else
|
||||
{
|
||||
m_tarName.prepend(m_tempDir->name());
|
||||
connect(Security::ref(), TQT_SIGNAL(validityResult(int)), this, TQT_SLOT(slotValidated(int)));
|
||||
Security::ref()->checkValidity(m_tarName);
|
||||
}
|
||||
} else
|
||||
ok = false;
|
||||
if (!ok)
|
||||
KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded resource tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("Resource Installation Error"));
|
||||
return ok;
|
||||
}
|
||||
|
||||
void KNewStuffSecure::slotValidated(int result)
|
||||
{
|
||||
TQString errorString;
|
||||
TQString signatureStr;
|
||||
bool valid = true;
|
||||
if (result == -1)
|
||||
{
|
||||
errorString ="<br>- " + i18n("No keys were found.");
|
||||
valid = false;
|
||||
} else
|
||||
if (result == 0)
|
||||
{
|
||||
errorString ="<br>- " + i18n("The validation failed for unknown reason.");
|
||||
valid = false;
|
||||
} else
|
||||
{
|
||||
KeyStruct key = Security::ref()->signatureKey();
|
||||
if (!(result & Security::MD5_OK ))
|
||||
{
|
||||
errorString = "<br>- " + i18n("The MD5SUM check failed, the archive might be broken.");
|
||||
valid = false;
|
||||
}
|
||||
if (result & Security::SIGNED_BAD)
|
||||
{
|
||||
errorString += "<br>- " + i18n("The signature is bad, the archive might be broken or altered.");
|
||||
valid = false;
|
||||
}
|
||||
if (result & Security::SIGNED_OK)
|
||||
{
|
||||
if (result & Security::TRUSTED)
|
||||
{
|
||||
kdDebug() << "Signed and trusted " << endl;
|
||||
} else
|
||||
{
|
||||
errorString += "<br>- " + i18n("The signature is valid, but untrusted.");
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
if (result & Security::UNKNOWN)
|
||||
{
|
||||
errorString += "<br>- " + i18n("The signature is unknown.");
|
||||
valid = false;
|
||||
} else
|
||||
{
|
||||
signatureStr = i18n("The resource was signed with key <i>0x%1</i>, belonging to <i>%2 <%3></i>.").arg(key.id.right(8)).arg(key.name).arg(key.mail);
|
||||
}
|
||||
}
|
||||
if (!valid)
|
||||
{
|
||||
signatureStr.prepend( "<br>");
|
||||
if (KMessageBox::warningContinueCancel(parentWidget(), i18n("<qt>There is a problem with the resource file you have downloaded. The errors are :<b>%1</b><br>%2<br><br>Installation of the resource is <b>not recommended</b>.<br><br>Do you want to proceed with the installation?</qt>").arg(errorString).arg(signatureStr), i18n("Problematic Resource File")) == KMessageBox::Continue)
|
||||
valid = true;
|
||||
} else
|
||||
KMessageBox::information(parentWidget(), i18n("<qt>%1<br><br>Press OK to install it.</qt>").arg(signatureStr), i18n("Valid Resource"), "Show Valid Signature Information");
|
||||
if (valid)
|
||||
{
|
||||
installResource();
|
||||
emit installFinished();
|
||||
} else
|
||||
{
|
||||
TDEConfig *cfg = TDEGlobal::config();
|
||||
cfg->deleteGroup("KNewStuffStatus");
|
||||
cfg->setGroup("KNewStuffStatus");
|
||||
for (TQMap<TQString, TQString>::ConstIterator it = m_installedResources.constBegin(); it != m_installedResources.constEnd(); ++it)
|
||||
{
|
||||
cfg->writeEntry(it.key(), it.data());
|
||||
}
|
||||
cfg->sync();
|
||||
}
|
||||
removeTempDirectory();
|
||||
disconnect(Security::ref(), TQT_SIGNAL(validityResult(int)), this, TQT_SLOT(slotValidated(int)));
|
||||
}
|
||||
|
||||
void KNewStuffSecure::downloadResource()
|
||||
{
|
||||
TDEConfig *cfg = TDEGlobal::config();
|
||||
m_installedResources = cfg->entryMap("KNewStuffStatus");
|
||||
engine()->ignoreInstallResult(true);
|
||||
KNewStuff::download();
|
||||
}
|
||||
|
||||
bool KNewStuffSecure::createUploadFile(const TQString &fileName)
|
||||
{
|
||||
Q_UNUSED(fileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
void KNewStuffSecure::uploadResource(const TQString& fileName)
|
||||
{
|
||||
connect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
|
||||
removeTempDirectory();
|
||||
m_tempDir = new KTempDir();
|
||||
m_tempDir->setAutoDelete(true);
|
||||
TQFileInfo f(fileName);
|
||||
m_signedFileName = m_tempDir->name() + "/" + f.fileName();
|
||||
TDEIO::NetAccess::file_copy(KURL::fromPathOrURL(fileName), KURL::fromPathOrURL(m_signedFileName), -1, true);
|
||||
Security::ref()->signFile(m_signedFileName);
|
||||
}
|
||||
|
||||
void KNewStuffSecure::slotFileSigned(int result)
|
||||
{
|
||||
if (result == 0)
|
||||
{
|
||||
KMessageBox::error(parentWidget(), i18n("The signing failed for unknown reason."));
|
||||
} else
|
||||
{
|
||||
if (result & Security::BAD_PASSPHRASE)
|
||||
{
|
||||
if (KMessageBox::warningContinueCancel(parentWidget(), i18n("There are no keys usable for signing or you did not entered the correct passphrase.\nProceed without signing the resource?")) == KMessageBox::Cancel)
|
||||
{
|
||||
disconnect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
|
||||
removeTempDirectory();
|
||||
return;
|
||||
}
|
||||
}
|
||||
KTar tar(m_signedFileName + ".signed", "application/x-gzip");
|
||||
tar.open(IO_WriteOnly);
|
||||
TQStringList files;
|
||||
files << m_signedFileName;
|
||||
files << m_tempDir->name() + "/md5sum";
|
||||
files << m_tempDir->name() + "/signature";
|
||||
|
||||
for (TQStringList::Iterator it_f = files.begin(); it_f != files.end(); ++it_f)
|
||||
{
|
||||
TQFile file(*it_f);
|
||||
file.open(IO_ReadOnly);
|
||||
TQByteArray bArray = file.readAll();
|
||||
tar.writeFile(TQFileInfo(file).fileName(), "user", "group", bArray.size(), bArray.data());
|
||||
file.close();
|
||||
}
|
||||
tar.close();
|
||||
TDEIO::NetAccess::file_move(KURL::fromPathOrURL(m_signedFileName + ".signed"), KURL::fromPathOrURL(m_signedFileName), -1, true);
|
||||
KNewStuff::upload(m_signedFileName, TQString());
|
||||
disconnect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
|
||||
}
|
||||
}
|
||||
|
||||
void KNewStuffSecure::slotUploadFinished(bool result)
|
||||
{
|
||||
Q_UNUSED(result);
|
||||
removeTempDirectory();
|
||||
}
|
||||
|
||||
void KNewStuffSecure::removeTempDirectory()
|
||||
{
|
||||
if (m_tempDir)
|
||||
{
|
||||
TDEIO::NetAccess::del(KURL().fromPathOrURL(m_tempDir->name()), parentWidget());
|
||||
delete m_tempDir;
|
||||
m_tempDir = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
#include "knewstuffsecure.moc"
|
@ -1,102 +0,0 @@
|
||||
/***************************************************************************
|
||||
knewstuffsecure.h - description
|
||||
-------------------
|
||||
begin : Tue Jun 22 12:19:55 2004
|
||||
copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; version 2 of the License. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef KNEWSTUFFSECURE_H
|
||||
#define KNEWSTUFFSECURE_H
|
||||
|
||||
//qt includes
|
||||
#include <tqobject.h>
|
||||
|
||||
//kde includes
|
||||
#include "knewstuff.h"
|
||||
|
||||
class KTempDir;
|
||||
/**
|
||||
Makes possible downloading and installing signed resource files from a server.
|
||||
You must subclass it and implement the @ref installResource() pure
|
||||
virtual method to install a resource. For uploading you must create a resource
|
||||
tarball (which is installabale by @ref installResource()) and call the
|
||||
@ref uploadResource() method with this tarball as the argument.
|
||||
Signing and verification is done by the gpg application, so the user must
|
||||
have it installed, otherwise this class does not give any extra security compared
|
||||
to the standard KNewStuff class.
|
||||
|
||||
@since 3.4
|
||||
|
||||
@author Andras Mantia <amantia@kde.org>
|
||||
*/
|
||||
class KDE_EXPORT KNewStuffSecure : public TQObject, public KNewStuff
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
/** Constructor.
|
||||
|
||||
@param type type of data to be handled, should be something like
|
||||
korganizer/calendar, kword/template, kdesktop/wallpaper
|
||||
@param parentWidget parent widget of dialogs opened by the KNewStuff
|
||||
engine
|
||||
*/
|
||||
KNewStuffSecure(const TQString &type, TQWidget *parentWidget=0);
|
||||
virtual ~KNewStuffSecure();
|
||||
|
||||
/** Installs the downloaded resource. Do not call or reimplement directly.
|
||||
It's reimplemented from KNewStuff for internal reasons.
|
||||
*/
|
||||
bool install( const TQString &fileName );
|
||||
|
||||
/** Reimplemented for internal reasons. */
|
||||
bool createUploadFile(const TQString &fileName);
|
||||
|
||||
/** Initiates a download. This is the method that must be called in
|
||||
* order to download a signed resource. */
|
||||
void downloadResource();
|
||||
|
||||
/** Signs the file and uploads to the central server.
|
||||
* @param fileName The file to be signed and uploaded
|
||||
*/
|
||||
void uploadResource(const TQString &fileName);
|
||||
|
||||
|
||||
private slots:
|
||||
/** Checks the validity of the downloaded tarball and installs it*/
|
||||
void slotValidated(int result);
|
||||
/** The file is signed, so it can be uploaded.*/
|
||||
void slotFileSigned(int result);
|
||||
/** Called when the upload has finished.
|
||||
@param result the result of the upload
|
||||
Be careful if you reimplement it, as it deletes the temporary directory
|
||||
m_tempDir used for upload. You must also delete it (call the parent's method)
|
||||
if you reimplement it.
|
||||
*/
|
||||
void slotUploadFinished(bool result);
|
||||
|
||||
signals:
|
||||
void installFinished();
|
||||
|
||||
protected:
|
||||
/** Installs the resource specified by m_tarName. Implement it in the subclass. */
|
||||
virtual void installResource() = 0;
|
||||
/** Removes the temporary directory m_tempDir. */
|
||||
void removeTempDirectory();
|
||||
|
||||
KTempDir *m_tempDir;
|
||||
TQString m_tarName;
|
||||
TQString m_signedFileName;
|
||||
TQMap<TQString, TQString> m_installedResources;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,223 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tdeconfig.h>
|
||||
#include <kdebug.h>
|
||||
#include <tdeio/job.h>
|
||||
#include <tdeglobal.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <tdelocale.h>
|
||||
|
||||
#include "provider.h"
|
||||
#include "provider.moc"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
Provider::Provider() : mNoUpload( false )
|
||||
{
|
||||
}
|
||||
|
||||
Provider::Provider( const TQDomElement &e ) : mNoUpload( false )
|
||||
{
|
||||
parseDomElement( e );
|
||||
}
|
||||
|
||||
Provider::~Provider()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Provider::setName( const TQString &name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
TQString Provider::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
void Provider::setIcon( const KURL &url )
|
||||
{
|
||||
mIcon = url;
|
||||
}
|
||||
|
||||
KURL Provider::icon() const
|
||||
{
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
|
||||
void Provider::setDownloadUrl( const KURL &url )
|
||||
{
|
||||
mDownloadUrl = url;
|
||||
}
|
||||
|
||||
KURL Provider::downloadUrl() const
|
||||
{
|
||||
return mDownloadUrl;
|
||||
}
|
||||
|
||||
|
||||
void Provider::setUploadUrl( const KURL &url )
|
||||
{
|
||||
mUploadUrl = url;
|
||||
}
|
||||
|
||||
KURL Provider::uploadUrl() const
|
||||
{
|
||||
return mUploadUrl;
|
||||
}
|
||||
|
||||
|
||||
void Provider::setNoUploadUrl( const KURL &url )
|
||||
{
|
||||
mNoUploadUrl = url;
|
||||
}
|
||||
|
||||
KURL Provider::noUploadUrl() const
|
||||
{
|
||||
return mNoUploadUrl;
|
||||
}
|
||||
|
||||
|
||||
void Provider::setNoUpload( bool enabled )
|
||||
{
|
||||
mNoUpload = enabled;
|
||||
}
|
||||
|
||||
bool Provider::noUpload() const
|
||||
{
|
||||
return mNoUpload;
|
||||
}
|
||||
|
||||
|
||||
void Provider::parseDomElement( const TQDomElement &element )
|
||||
{
|
||||
if ( element.tagName() != "provider" ) return;
|
||||
|
||||
setDownloadUrl( KURL( element.attribute("downloadurl") ) );
|
||||
setUploadUrl( KURL( element.attribute("uploadurl") ) );
|
||||
setNoUploadUrl( KURL( element.attribute("nouploadurl") ) );
|
||||
setIcon( KURL( element.attribute("icon") ) );
|
||||
|
||||
TQDomNode n;
|
||||
for ( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||||
TQDomElement p = n.toElement();
|
||||
|
||||
if ( p.tagName() == "noupload" ) setNoUpload( true );
|
||||
if ( p.tagName() == "title" ) setName( p.text().stripWhiteSpace() );
|
||||
}
|
||||
}
|
||||
|
||||
TQDomElement Provider::createDomElement( TQDomDocument &doc, TQDomElement &parent )
|
||||
{
|
||||
TQDomElement entry = doc.createElement( "stuff" );
|
||||
parent.appendChild( entry );
|
||||
|
||||
TQDomElement n = doc.createElement( "name" );
|
||||
n.appendChild( doc.createTextNode( name() ) );
|
||||
entry.appendChild( n );
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
ProviderLoader::ProviderLoader( TQWidget *parentWidget ) :
|
||||
mParentWidget( parentWidget )
|
||||
{
|
||||
mProviders.setAutoDelete( true );
|
||||
}
|
||||
|
||||
void ProviderLoader::load( const TQString &type, const TQString &providersList )
|
||||
{
|
||||
kdDebug(5850) << "ProviderLoader::load()" << endl;
|
||||
|
||||
mProviders.clear();
|
||||
mJobData = "";
|
||||
|
||||
TDEConfig *cfg = TDEGlobal::config();
|
||||
cfg->setGroup("KNewStuff");
|
||||
|
||||
TQString providersUrl = providersList;
|
||||
if( providersUrl.isEmpty() )
|
||||
providersUrl = cfg->readEntry( "ProvidersUrl" );
|
||||
|
||||
if ( providersUrl.isEmpty() ) {
|
||||
// TODO: Replace the default by the real one.
|
||||
TQString server = cfg->readEntry( "MasterServer",
|
||||
"http://korganizer.kde.org" );
|
||||
|
||||
providersUrl = server + "/knewstuff/" + type + "/providers.xml";
|
||||
}
|
||||
|
||||
kdDebug(5850) << "ProviderLoader::load(): providersUrl: " << providersUrl << endl;
|
||||
|
||||
TDEIO::TransferJob *job = TDEIO::get( KURL( providersUrl ) );
|
||||
connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||||
TQT_SLOT( slotJobResult( TDEIO::Job * ) ) );
|
||||
connect( job, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ),
|
||||
TQT_SLOT( slotJobData( TDEIO::Job *, const TQByteArray & ) ) );
|
||||
|
||||
// job->dumpObjectInfo();
|
||||
}
|
||||
|
||||
void ProviderLoader::slotJobData( TDEIO::Job *, const TQByteArray &data )
|
||||
{
|
||||
kdDebug(5850) << "ProviderLoader::slotJobData()" << endl;
|
||||
|
||||
if ( data.size() == 0 ) return;
|
||||
|
||||
TQCString str( data, data.size() + 1 );
|
||||
|
||||
mJobData.append( TQString::fromUtf8( str ) );
|
||||
}
|
||||
|
||||
void ProviderLoader::slotJobResult( TDEIO::Job *job )
|
||||
{
|
||||
if ( job->error() ) {
|
||||
job->showErrorDialog( mParentWidget );
|
||||
}
|
||||
|
||||
kdDebug(5850) << "--PROVIDERS-START--" << endl << mJobData << "--PROV_END--"
|
||||
<< endl;
|
||||
|
||||
TQDomDocument doc;
|
||||
if ( !doc.setContent( mJobData ) ) {
|
||||
KMessageBox::error( mParentWidget, i18n("Error parsing providers list.") );
|
||||
return;
|
||||
}
|
||||
|
||||
TQDomElement providers = doc.documentElement();
|
||||
|
||||
if ( providers.isNull() ) {
|
||||
kdDebug(5850) << "No document in Providers.xml." << endl;
|
||||
}
|
||||
|
||||
TQDomNode n;
|
||||
for ( n = providers.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||||
TQDomElement p = n.toElement();
|
||||
|
||||
mProviders.append( new Provider( p ) );
|
||||
}
|
||||
|
||||
emit providersLoaded( &mProviders );
|
||||
}
|
@ -1,207 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_PROVIDER_H
|
||||
#define KNEWSTUFF_PROVIDER_H
|
||||
|
||||
#include <tqcstring.h>
|
||||
#include <tqdom.h>
|
||||
#include <tqobject.h>
|
||||
#include <tqptrlist.h>
|
||||
#include <tqstring.h>
|
||||
|
||||
#include <kurl.h>
|
||||
|
||||
namespace TDEIO { class Job; }
|
||||
|
||||
namespace KNS {
|
||||
|
||||
/**
|
||||
* @short KNewStuff provider container.
|
||||
*
|
||||
* This class provides accessors for the provider object.
|
||||
* as used by KNewStuff.
|
||||
* It should probably not be used directly by the application.
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class Provider
|
||||
{
|
||||
public:
|
||||
typedef TQPtrList<Provider> List;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Provider();
|
||||
|
||||
/**
|
||||
* Constructor with XML feed.
|
||||
*/
|
||||
Provider( const TQDomElement & );
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Provider();
|
||||
|
||||
/**
|
||||
* Sets the common name of the provider.
|
||||
*/
|
||||
void setName( const TQString & );
|
||||
|
||||
/**
|
||||
* Retrieves the common name of the provider.
|
||||
*
|
||||
* @return provider name
|
||||
*/
|
||||
TQString name() const;
|
||||
|
||||
/**
|
||||
* Sets the download URL.
|
||||
*/
|
||||
void setDownloadUrl( const KURL & );
|
||||
|
||||
/**
|
||||
* Retrieves the download URL.
|
||||
*
|
||||
* @return download URL
|
||||
*/
|
||||
KURL downloadUrl() const;
|
||||
|
||||
/**
|
||||
* Sets the upload URL.
|
||||
*/
|
||||
void setUploadUrl( const KURL & );
|
||||
|
||||
/**
|
||||
* Retrieves the upload URL.
|
||||
*
|
||||
* @return upload URL
|
||||
*/
|
||||
KURL uploadUrl() const;
|
||||
|
||||
/**
|
||||
* Sets the URL where a user is led if the provider does not support
|
||||
* uploads.
|
||||
*
|
||||
* @see setNoUpload
|
||||
*/
|
||||
void setNoUploadUrl( const KURL & );
|
||||
|
||||
/**
|
||||
* Retrieves the URL where a user is led if the provider does not
|
||||
* support uploads.
|
||||
*
|
||||
* @return website URL
|
||||
*/
|
||||
KURL noUploadUrl() const;
|
||||
|
||||
/**
|
||||
* Indicate whether provider supports uploads.
|
||||
*/
|
||||
void setNoUpload( bool );
|
||||
|
||||
/**
|
||||
* Query whether provider supports uploads.
|
||||
*
|
||||
* @return upload support status
|
||||
*/
|
||||
bool noUpload() const;
|
||||
|
||||
/**
|
||||
* Sets the URL for an icon for this provider.
|
||||
* The icon should be in 32x32 format. If not set, the default icon
|
||||
* of KDialogBase is used.
|
||||
*/
|
||||
void setIcon( const KURL & );
|
||||
|
||||
/**
|
||||
* Retrieves the icon URL for this provider.
|
||||
*
|
||||
* @return icon URL
|
||||
*/
|
||||
KURL icon() const;
|
||||
|
||||
protected:
|
||||
void parseDomElement( const TQDomElement & );
|
||||
|
||||
TQDomElement createDomElement( TQDomDocument &, TQDomElement &parent );
|
||||
|
||||
private:
|
||||
TQString mName;
|
||||
KURL mDownloadUrl;
|
||||
KURL mUploadUrl;
|
||||
KURL mNoUploadUrl;
|
||||
KURL mIcon;
|
||||
bool mNoUpload;
|
||||
};
|
||||
|
||||
/**
|
||||
* KNewStuff provider loader.
|
||||
* This class sets up a list of all possible providers by querying
|
||||
* the main provider database for this specific application.
|
||||
* It should probably not be used directly by the application.
|
||||
*/
|
||||
class ProviderLoader : public TQObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param parentWidget the parent widget
|
||||
*/
|
||||
ProviderLoader( TQWidget *parentWidget );
|
||||
|
||||
/**
|
||||
* Starts asynchronously loading the list of providers of the
|
||||
* specified type.
|
||||
*
|
||||
* @param type data type such as 'kdesktop/wallpaper'.
|
||||
* @param providerList the URl to the list of providers; if empty
|
||||
* we first try the ProvidersUrl from TDEGlobal::config, then we
|
||||
* fall back to a hardcoded value.
|
||||
*/
|
||||
void load( const TQString &type, const TQString &providerList = TQString() );
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Indicates that the list of providers has been successfully loaded.
|
||||
*/
|
||||
void providersLoaded( Provider::List * );
|
||||
|
||||
protected slots:
|
||||
void slotJobData( TDEIO::Job *, const TQByteArray & );
|
||||
void slotJobResult( TDEIO::Job * );
|
||||
|
||||
private:
|
||||
TQWidget *mParentWidget;
|
||||
|
||||
TQString mJobData;
|
||||
|
||||
Provider::List mProviders;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tqlayout.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqlabel.h>
|
||||
|
||||
#include <tdelistview.h>
|
||||
#include <tdelocale.h>
|
||||
#include <tdemessagebox.h>
|
||||
|
||||
#include "engine.h"
|
||||
#include "provider.h"
|
||||
|
||||
#include "providerdialog.h"
|
||||
#include "providerdialog.moc"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
class ProviderItem : public TDEListViewItem
|
||||
{
|
||||
public:
|
||||
ProviderItem( TDEListView *parent, Provider *provider ) :
|
||||
TDEListViewItem( parent ), mProvider( provider )
|
||||
{
|
||||
setText( 0, provider->name() );
|
||||
}
|
||||
|
||||
Provider *provider() { return mProvider; }
|
||||
|
||||
private:
|
||||
Provider *mProvider;
|
||||
};
|
||||
|
||||
ProviderDialog::ProviderDialog( Engine *engine, TQWidget *parent ) :
|
||||
KDialogBase( Plain, i18n("Hot New Stuff Providers"), Ok | Cancel, Cancel,
|
||||
parent, 0, false, true ),
|
||||
mEngine( engine )
|
||||
{
|
||||
TQFrame *topPage = plainPage();
|
||||
|
||||
TQBoxLayout *topLayout = new TQVBoxLayout( topPage );
|
||||
|
||||
TQLabel *description = new TQLabel( i18n("Please select one of the providers listed below:"), topPage );
|
||||
topLayout->addWidget( description );
|
||||
|
||||
mListView = new TDEListView( topPage );
|
||||
mListView->addColumn( i18n("Name") );
|
||||
topLayout->addWidget( mListView );
|
||||
}
|
||||
|
||||
void ProviderDialog::clear()
|
||||
{
|
||||
mListView->clear();
|
||||
}
|
||||
|
||||
void ProviderDialog::addProvider( Provider *provider )
|
||||
{
|
||||
new ProviderItem( mListView, provider );
|
||||
if ( mListView->childCount() == 1 ) {
|
||||
mListView->setSelected(mListView->firstChild(), true);
|
||||
} else if (mListView->childCount() > 1) {
|
||||
mListView->setSelected(mListView->firstChild(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void ProviderDialog::slotOk()
|
||||
{
|
||||
ProviderItem *item = static_cast<ProviderItem *>( mListView->selectedItem() );
|
||||
if ( !item ) {
|
||||
KMessageBox::error( this, i18n("No provider selected.") );
|
||||
return;
|
||||
}
|
||||
|
||||
mEngine->requestMetaInformation( item->provider() );
|
||||
|
||||
accept();
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_PROVIDERDIALOG_H
|
||||
#define KNEWSTUFF_PROVIDERDIALOG_H
|
||||
|
||||
#include <kdialogbase.h>
|
||||
|
||||
class TDEListView;
|
||||
|
||||
namespace KNS {
|
||||
|
||||
class Provider;
|
||||
class Engine;
|
||||
|
||||
/**
|
||||
* @short Dialog displaying a list of Hotstuff providers.
|
||||
*
|
||||
* This is normally used in the process of uploading data, thus limiting the
|
||||
* list to providers which support uploads.
|
||||
* One of the providers is then chosen by the user for further operation.
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class ProviderDialog : public KDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param engine a KNewStuff engine object
|
||||
@param parent the parent window
|
||||
*/
|
||||
ProviderDialog( Engine *engine, TQWidget *parent );
|
||||
|
||||
/**
|
||||
Clears the list of providers.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
Adds a Hotstuff provider to the list.
|
||||
*/
|
||||
void addProvider( Provider * );
|
||||
|
||||
protected slots:
|
||||
void slotOk();
|
||||
|
||||
private:
|
||||
Engine *mEngine;
|
||||
|
||||
TDEListView *mListView;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,344 +0,0 @@
|
||||
/***************************************************************************
|
||||
security.cpp - description
|
||||
-------------------
|
||||
begin : Thu Jun 24 11:22:12 2004
|
||||
copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; version 2 of the License. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
//qt includes
|
||||
#include <tqfile.h>
|
||||
#include <tqfileinfo.h>
|
||||
#include <tqstringlist.h>
|
||||
#include <tqtimer.h>
|
||||
|
||||
//kde includes
|
||||
#include <kdebug.h>
|
||||
#include <kinputdialog.h>
|
||||
#include <tdelocale.h>
|
||||
#include <kmdcodec.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <kpassdlg.h>
|
||||
#include <kprocio.h>
|
||||
|
||||
//app includes
|
||||
#include "security.h"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
Security::Security()
|
||||
{
|
||||
m_keysRead = false;
|
||||
m_gpgRunning = false;
|
||||
readKeys();
|
||||
readSecretKeys();
|
||||
}
|
||||
|
||||
|
||||
Security::~Security()
|
||||
{
|
||||
}
|
||||
|
||||
void Security::readKeys()
|
||||
{
|
||||
if (m_gpgRunning)
|
||||
{
|
||||
TQTimer::singleShot(5, this, TQT_SLOT(readKeys()));
|
||||
return;
|
||||
}
|
||||
m_runMode = List;
|
||||
m_keys.clear();
|
||||
KProcIO *readProcess=new KProcIO();
|
||||
*readProcess << "gpg"<<"--no-secmem-warning"<<"--no-tty"<<"--with-colon"<<"--list-keys";
|
||||
connect(readProcess, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(slotProcessExited(TDEProcess *)));
|
||||
connect(readProcess, TQT_SIGNAL(readReady(KProcIO *)) ,this, TQT_SLOT(slotDataArrived(KProcIO *)));
|
||||
if (!readProcess->start(TDEProcess::NotifyOnExit, true))
|
||||
KMessageBox::error(0L, i18n("<qt>Cannot start <i>gpg</i> and retrieve the available keys. Make sure that <i>gpg</i> is installed, otherwise verification of downloaded resources will not be possible.</qt>"));
|
||||
else
|
||||
m_gpgRunning = true;
|
||||
}
|
||||
|
||||
void Security::readSecretKeys()
|
||||
{
|
||||
if (m_gpgRunning)
|
||||
{
|
||||
TQTimer::singleShot(5, this, TQT_SLOT(readSecretKeys()));
|
||||
return;
|
||||
}
|
||||
m_runMode = ListSecret;
|
||||
KProcIO *readProcess=new KProcIO();
|
||||
*readProcess << "gpg"<<"--no-secmem-warning"<<"--no-tty"<<"--with-colon"<<"--list-secret-keys";
|
||||
connect(readProcess, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(slotProcessExited(TDEProcess *)));
|
||||
connect(readProcess, TQT_SIGNAL(readReady(KProcIO *)) ,this, TQT_SLOT(slotDataArrived(KProcIO *)));
|
||||
if (readProcess->start(TDEProcess::NotifyOnExit, true))
|
||||
m_gpgRunning = true;
|
||||
}
|
||||
|
||||
void Security::slotProcessExited(TDEProcess *process)
|
||||
{
|
||||
switch (m_runMode)
|
||||
{
|
||||
case ListSecret:
|
||||
m_keysRead = true;
|
||||
break;
|
||||
case Verify: emit validityResult(m_result);
|
||||
break;
|
||||
case Sign: emit fileSigned(m_result);
|
||||
break;
|
||||
|
||||
}
|
||||
m_gpgRunning = false;
|
||||
delete process;
|
||||
}
|
||||
|
||||
void Security::slotDataArrived(KProcIO *procIO)
|
||||
{
|
||||
TQString data;
|
||||
while (procIO->readln(data, true) != -1)
|
||||
{
|
||||
switch (m_runMode)
|
||||
{
|
||||
case List:
|
||||
case ListSecret:
|
||||
if (data.startsWith("pub") || data.startsWith("sec"))
|
||||
{
|
||||
KeyStruct key;
|
||||
if (data.startsWith("pub"))
|
||||
key.secret = false;
|
||||
else
|
||||
key.secret = true;
|
||||
TQStringList line = TQStringList::split(":", data, true);
|
||||
key.id = line[4];
|
||||
TQString shortId = key.id.right(8);
|
||||
TQString trustStr = line[1];
|
||||
key.trusted = false;
|
||||
if (trustStr == "u" || trustStr == "f")
|
||||
key.trusted = true;
|
||||
data = line[9];
|
||||
key.mail=data.section('<', -1, -1);
|
||||
key.mail.truncate(key.mail.length() - 1);
|
||||
key.name=data.section('<',0,0);
|
||||
if (key.name.find("(")!=-1)
|
||||
key.name=key.name.section('(',0,0);
|
||||
m_keys[shortId] = key;
|
||||
}
|
||||
break;
|
||||
case Verify:
|
||||
data = data.section("]",1,-1).stripWhiteSpace();
|
||||
if (data.startsWith("GOODSIG"))
|
||||
{
|
||||
m_result &= SIGNED_BAD_CLEAR;
|
||||
m_result |= SIGNED_OK;
|
||||
TQString id = data.section(" ", 1 , 1).right(8);
|
||||
if (!m_keys.contains(id))
|
||||
{
|
||||
m_result |= UNKNOWN;
|
||||
} else
|
||||
{
|
||||
m_signatureKey = m_keys[id];
|
||||
}
|
||||
} else
|
||||
if (data.startsWith("NO_PUBKEY"))
|
||||
{
|
||||
m_result &= SIGNED_BAD_CLEAR;
|
||||
m_result |= UNKNOWN;
|
||||
} else
|
||||
if (data.startsWith("BADSIG"))
|
||||
{
|
||||
m_result |= SIGNED_BAD;
|
||||
TQString id = data.section(" ", 1 , 1).right(8);
|
||||
if (!m_keys.contains(id))
|
||||
{
|
||||
m_result |= UNKNOWN;
|
||||
} else
|
||||
{
|
||||
m_signatureKey = m_keys[id];
|
||||
}
|
||||
} else
|
||||
if (data.startsWith("TRUST_ULTIMATE"))
|
||||
{
|
||||
m_result &= SIGNED_BAD_CLEAR;
|
||||
m_result |= TRUSTED;
|
||||
}
|
||||
break;
|
||||
|
||||
case Sign:
|
||||
if (data.find("passphrase.enter") != -1)
|
||||
{
|
||||
TQCString password;
|
||||
KeyStruct key = m_keys[m_secretKey];
|
||||
int result = KPasswordDialog::getPassword(password, i18n("<qt>Enter passphrase for key <b>0x%1</b>, belonging to<br><i>%2<%3></i>:</qt>").arg(m_secretKey).arg(key.name).arg(key.mail));
|
||||
if (result == KPasswordDialog::Accepted)
|
||||
{
|
||||
procIO->writeStdin(password, true);
|
||||
password.fill(' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
m_result |= BAD_PASSPHRASE;
|
||||
slotProcessExited(procIO);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
if (data.find("BAD_PASSPHRASE") != -1)
|
||||
{
|
||||
m_result |= BAD_PASSPHRASE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Security::checkValidity(const TQString& filename)
|
||||
{
|
||||
m_fileName = filename;
|
||||
slotCheckValidity();
|
||||
}
|
||||
|
||||
void Security::slotCheckValidity()
|
||||
{
|
||||
if (!m_keysRead || m_gpgRunning)
|
||||
{
|
||||
TQTimer::singleShot(5, this, TQT_SLOT(slotCheckValidity()));
|
||||
return;
|
||||
}
|
||||
if (m_keys.count() == 0)
|
||||
{
|
||||
emit validityResult(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
m_result = 0;
|
||||
m_runMode = Verify;
|
||||
TQFileInfo f(m_fileName);
|
||||
//check the MD5 sum
|
||||
TQString md5sum;
|
||||
const char* c = "";
|
||||
KMD5 context(c);
|
||||
TQFile file(m_fileName);
|
||||
if (file.open(IO_ReadOnly))
|
||||
{
|
||||
context.reset();
|
||||
context.update(file);
|
||||
md5sum = context.hexDigest();
|
||||
file.close();
|
||||
}
|
||||
file.setName(f.dirPath() + "/md5sum");
|
||||
if (file.open(IO_ReadOnly))
|
||||
{
|
||||
TQString md5sum_file;
|
||||
file.readLine(md5sum_file, 50);
|
||||
if (!md5sum.isEmpty() && !md5sum_file.isEmpty() && md5sum_file.startsWith(md5sum))
|
||||
m_result |= MD5_OK;
|
||||
file.close();
|
||||
}
|
||||
m_result |= SIGNED_BAD;
|
||||
m_signatureKey.id = "";
|
||||
m_signatureKey.name = "";
|
||||
m_signatureKey.mail = "";
|
||||
m_signatureKey.trusted = false;
|
||||
|
||||
//verify the signature
|
||||
KProcIO *verifyProcess=new KProcIO();
|
||||
*verifyProcess<<"gpg"<<"--no-secmem-warning"<<"--status-fd=2"<<"--command-fd=0"<<"--verify" << f.dirPath() + "/signature"<< m_fileName;
|
||||
connect(verifyProcess, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotProcessExited(TDEProcess *)));
|
||||
connect(verifyProcess, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotDataArrived(KProcIO *)));
|
||||
if (verifyProcess->start(TDEProcess::NotifyOnExit,true))
|
||||
m_gpgRunning = true;
|
||||
else
|
||||
{
|
||||
KMessageBox::error(0L, i18n("<qt>Cannot start <i>gpg</i> and check the validity of the file. Make sure that <i>gpg</i> is installed, otherwise verification of downloaded resources will not be possible.</qt>"));
|
||||
emit validityResult(0);
|
||||
delete verifyProcess;
|
||||
}
|
||||
}
|
||||
|
||||
void Security::signFile(const TQString &fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
slotSignFile();
|
||||
}
|
||||
|
||||
void Security::slotSignFile()
|
||||
{
|
||||
if (!m_keysRead || m_gpgRunning)
|
||||
{
|
||||
TQTimer::singleShot(5, this, TQT_SLOT(slotSignFile()));
|
||||
return;
|
||||
}
|
||||
|
||||
TQStringList secretKeys;
|
||||
for (TQMap<TQString, KeyStruct>::Iterator it = m_keys.begin(); it != m_keys.end(); ++it)
|
||||
{
|
||||
if (it.data().secret)
|
||||
secretKeys.append(it.key());
|
||||
}
|
||||
|
||||
if (secretKeys.count() == 0)
|
||||
{
|
||||
emit fileSigned(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
m_result = 0;
|
||||
TQFileInfo f(m_fileName);
|
||||
|
||||
//create the MD5 sum
|
||||
TQString md5sum;
|
||||
const char* c = "";
|
||||
KMD5 context(c);
|
||||
TQFile file(m_fileName);
|
||||
if (file.open(IO_ReadOnly))
|
||||
{
|
||||
context.reset();
|
||||
context.update(file);
|
||||
md5sum = context.hexDigest();
|
||||
file.close();
|
||||
}
|
||||
file.setName(f.dirPath() + "/md5sum");
|
||||
if (file.open(IO_WriteOnly))
|
||||
{
|
||||
TQTextStream stream(&file);
|
||||
stream << md5sum;
|
||||
m_result |= MD5_OK;
|
||||
file.close();
|
||||
}
|
||||
|
||||
if (secretKeys.count() > 1)
|
||||
{
|
||||
bool ok;
|
||||
secretKeys = KInputDialog::getItemList(i18n("Select Signing Key"), i18n("Key used for signing:"), secretKeys, secretKeys[0], false, &ok);
|
||||
if (ok)
|
||||
m_secretKey = secretKeys[0];
|
||||
else
|
||||
{
|
||||
emit fileSigned(0);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
m_secretKey = secretKeys[0];
|
||||
|
||||
//verify the signature
|
||||
KProcIO *signProcess=new KProcIO();
|
||||
*signProcess<<"gpg"<<"--no-secmem-warning"<<"--status-fd=2"<<"--command-fd=0"<<"--no-tty"<<"--detach-sign" << "-u" << m_secretKey << "-o" << f.dirPath() + "/signature" << m_fileName;
|
||||
connect(signProcess, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotProcessExited(TDEProcess *)));
|
||||
connect(signProcess, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotDataArrived(KProcIO *)));
|
||||
m_runMode = Sign;
|
||||
if (signProcess->start(TDEProcess::NotifyOnExit,true))
|
||||
m_gpgRunning = true;
|
||||
else
|
||||
{
|
||||
KMessageBox::error(0L, i18n("<qt>Cannot start <i>gpg</i> and sign the file. Make sure that <i>gpg</i> is installed, otherwise signing of the resources will not be possible.</qt>"));
|
||||
emit fileSigned(0);
|
||||
delete signProcess;
|
||||
}
|
||||
}
|
||||
|
||||
#include "security.moc"
|
@ -1,142 +0,0 @@
|
||||
/***************************************************************************
|
||||
security.h - description
|
||||
-------------------
|
||||
begin : Thu Jun 24 11:22:12 2004
|
||||
copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; version 2 of the License. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SECURITY_H
|
||||
#define SECURITY_H
|
||||
|
||||
//qt includes
|
||||
#include <tqmap.h>
|
||||
#include <tqobject.h>
|
||||
|
||||
class KProcIO;
|
||||
class TDEProcess;
|
||||
|
||||
struct KeyStruct {
|
||||
TQString id;
|
||||
TQString name;
|
||||
TQString mail;
|
||||
bool trusted;
|
||||
bool secret;
|
||||
};
|
||||
|
||||
/**
|
||||
Handles security releated issues, like signing, verifying.
|
||||
It is a private class, not meant to be used by third party applications.
|
||||
|
||||
@author Andras Mantia <amantia@kde.org>
|
||||
*/
|
||||
|
||||
namespace KNS {
|
||||
|
||||
class Security : public TQObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static Security* const ref()
|
||||
{
|
||||
static Security *m_ref;
|
||||
if (!m_ref) m_ref = new Security();
|
||||
return m_ref;
|
||||
}
|
||||
~Security();
|
||||
|
||||
|
||||
/** Verifies the integrity and the signature of a tarball file.
|
||||
* @param fileName the file to be verified. It should be a tar.gz (.tgz) file. The directory where
|
||||
* the file is should contain a "signature" and a "md5sum" file, otherwise verification will fail.
|
||||
* The method is asynchronous and the result is signalled with @ref validityResult.
|
||||
*/
|
||||
void checkValidity(const TQString &fileName);
|
||||
|
||||
/** Creates a signature and an md5sum file for the fileName and packs
|
||||
* everything into a gzipped tarball.
|
||||
* @param fileName the file with full path to sign
|
||||
*
|
||||
* The method is asynchronous and the result is signalled with @ref fileSigned.
|
||||
*/
|
||||
void signFile(const TQString &fileName);
|
||||
/** Get the key used for signing. This method is valid only if:
|
||||
* - the checkValidity was called
|
||||
* - the result of the validity check does not have the UNKNOWN bit set
|
||||
*
|
||||
* @return the key used for signing the file
|
||||
*/
|
||||
KeyStruct signatureKey() {return m_signatureKey;}
|
||||
|
||||
enum Results {
|
||||
MD5_OK = 1, /// The MD5 sum check is OK
|
||||
SIGNED_OK = 2, /// The file is signed with a good signature
|
||||
SIGNED_BAD = 4, /// The file is signed with a bad signature
|
||||
TRUSTED = 8, /// The signature is trusted
|
||||
UNKNOWN = 16, ///The key is unknown
|
||||
SIGNED_BAD_CLEAR = 27, ///used to clear the SIGNED_BAD flag
|
||||
BAD_PASSPHRASE = 32 ///wrong passhprase entered
|
||||
};
|
||||
|
||||
public slots:
|
||||
/** Reads the available public keys */
|
||||
void readKeys();
|
||||
/** Reads the available secret keys */
|
||||
void readSecretKeys();
|
||||
/** Verifies the integrity and the signature of a tarball file (@see m_fileName).
|
||||
*/
|
||||
void slotCheckValidity();
|
||||
|
||||
/** Creates a signature and an md5sum file for the @see m_fileName and packs
|
||||
* everything into a gzipped tarball.
|
||||
*/
|
||||
void slotSignFile();
|
||||
|
||||
private:
|
||||
Security();
|
||||
|
||||
enum RunMode {
|
||||
List = 0, ///read the public keys
|
||||
ListSecret, ///read the secret keys
|
||||
Verify, ///verify the signature
|
||||
Sign ///create signature
|
||||
};
|
||||
|
||||
KeyStruct m_signatureKey;
|
||||
int m_result;
|
||||
int m_runMode;
|
||||
bool m_gpgRunning; /// true if gpg is currently running
|
||||
bool m_keysRead; /// true if all the keys were read
|
||||
TQMap<TQString, KeyStruct> m_keys; /// holds information about the available key
|
||||
TQString m_fileName; /// the file to sign/verify
|
||||
TQString m_secretKey; /// the key used for signing
|
||||
|
||||
private slots:
|
||||
void slotProcessExited(TDEProcess *process);
|
||||
void slotDataArrived(KProcIO *process);
|
||||
|
||||
signals:
|
||||
/** Sent when the validity check is done.
|
||||
*
|
||||
* @return the result of the check. See @ref Results
|
||||
*/
|
||||
void validityResult(int result);
|
||||
/** Sent when the signing is done.
|
||||
*
|
||||
* @return the result of the operation. See @ref Results
|
||||
*/
|
||||
void fileSigned(int result);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,176 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tqcombobox.h>
|
||||
#include <tqlabel.h>
|
||||
#include <tqlayout.h>
|
||||
#include <tqlineedit.h>
|
||||
#include <tqspinbox.h>
|
||||
#include <tqstring.h>
|
||||
#include <ktextedit.h>
|
||||
|
||||
#include <tdelistview.h>
|
||||
#include <tdelocale.h>
|
||||
#include <kdebug.h>
|
||||
#include <kurlrequester.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <tdeconfig.h>
|
||||
#include <tdeapplication.h>
|
||||
|
||||
#include "engine.h"
|
||||
#include "entry.h"
|
||||
|
||||
#include "uploaddialog.h"
|
||||
#include "uploaddialog.moc"
|
||||
|
||||
using namespace KNS;
|
||||
|
||||
UploadDialog::UploadDialog( Engine *engine, TQWidget *parent ) :
|
||||
KDialogBase( Plain, i18n("Share Hot New Stuff"), Ok | Cancel, Cancel,
|
||||
parent, 0, false, true ),
|
||||
mEngine( engine )
|
||||
{
|
||||
mEntryList.setAutoDelete( true );
|
||||
|
||||
TQFrame *topPage = plainPage();
|
||||
|
||||
TQGridLayout *topLayout = new TQGridLayout( topPage );
|
||||
topLayout->setSpacing( spacingHint() );
|
||||
|
||||
TQLabel *nameLabel = new TQLabel( i18n("Name:"), topPage );
|
||||
topLayout->addWidget( nameLabel, 0, 0 );
|
||||
mNameEdit = new TQLineEdit( topPage );
|
||||
topLayout->addWidget( mNameEdit, 0, 1 );
|
||||
|
||||
TQLabel *authorLabel = new TQLabel( i18n("Author:"), topPage );
|
||||
topLayout->addWidget( authorLabel, 1, 0 );
|
||||
mAuthorEdit = new TQLineEdit( topPage );
|
||||
topLayout->addWidget( mAuthorEdit, 1, 1 );
|
||||
|
||||
TQLabel *versionLabel = new TQLabel( i18n("Version:"), topPage );
|
||||
topLayout->addWidget( versionLabel, 2, 0 );
|
||||
mVersionEdit = new TQLineEdit( topPage );
|
||||
topLayout->addWidget( mVersionEdit, 2, 1 );
|
||||
|
||||
TQLabel *releaseLabel = new TQLabel( i18n("Release:"), topPage );
|
||||
topLayout->addWidget( releaseLabel, 3, 0 );
|
||||
mReleaseSpin = new TQSpinBox( topPage );
|
||||
mReleaseSpin->setMinValue( 1 );
|
||||
topLayout->addWidget( mReleaseSpin, 3, 1 );
|
||||
|
||||
TQLabel *licenceLabel = new TQLabel( i18n("License:"), topPage );
|
||||
topLayout->addWidget( licenceLabel, 4, 0 );
|
||||
mLicenceCombo = new TQComboBox( topPage );
|
||||
mLicenceCombo->setEditable( true );
|
||||
mLicenceCombo->insertItem( i18n("GPL") );
|
||||
mLicenceCombo->insertItem( i18n("LGPL") );
|
||||
mLicenceCombo->insertItem( i18n("BSD") );
|
||||
topLayout->addWidget( mLicenceCombo, 4, 1 );
|
||||
|
||||
TQLabel *languageLabel = new TQLabel( i18n("Language:"), topPage );
|
||||
topLayout->addWidget( languageLabel, 5, 0 );
|
||||
mLanguageCombo = new TQComboBox( topPage );
|
||||
topLayout->addWidget( mLanguageCombo, 5, 1 );
|
||||
mLanguageCombo->insertStringList( TDEGlobal::locale()->languageList() );
|
||||
|
||||
TQLabel *previewLabel = new TQLabel( i18n("Preview URL:"), topPage );
|
||||
topLayout->addWidget( previewLabel, 6, 0 );
|
||||
mPreviewUrl = new KURLRequester( topPage );
|
||||
topLayout->addWidget( mPreviewUrl, 6, 1 );
|
||||
|
||||
TQLabel *summaryLabel = new TQLabel( i18n("Summary:"), topPage );
|
||||
topLayout->addMultiCellWidget( summaryLabel, 7, 7, 0, 1 );
|
||||
mSummaryEdit = new KTextEdit( topPage );
|
||||
topLayout->addMultiCellWidget( mSummaryEdit, 8, 8, 0, 1 );
|
||||
|
||||
TDEConfig *conf = kapp->config();
|
||||
conf->setGroup("KNewStuffUpload");
|
||||
TQString name = conf->readEntry("name");
|
||||
TQString author = conf->readEntry("author");
|
||||
TQString version = conf->readEntry("version");
|
||||
TQString release = conf->readEntry("release");
|
||||
TQString preview = conf->readEntry("preview");
|
||||
TQString summary = conf->readEntry("summary");
|
||||
TQString lang = conf->readEntry("language");
|
||||
TQString licence = conf->readEntry("licence");
|
||||
|
||||
if(!name.isNull())
|
||||
{
|
||||
int prefill = KMessageBox::questionYesNo(this, i18n("Old upload information found, fill out fields?"), TQString(), i18n("Fill Out Fields"), i18n("Do Not Fill Out"));
|
||||
if(prefill == KMessageBox::Yes)
|
||||
{
|
||||
mNameEdit->setText(name);
|
||||
mAuthorEdit->setText(author);
|
||||
mVersionEdit->setText(version);
|
||||
mReleaseSpin->setValue(release.toInt());
|
||||
mPreviewUrl->setURL(preview);
|
||||
mSummaryEdit->setText(summary);
|
||||
if(!lang.isEmpty()) mLanguageCombo->setCurrentText(lang);
|
||||
if(!licence.isEmpty()) mLicenceCombo->setCurrentText(licence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UploadDialog::~UploadDialog()
|
||||
{
|
||||
mEntryList.clear();
|
||||
}
|
||||
|
||||
void UploadDialog::slotOk()
|
||||
{
|
||||
if ( mNameEdit->text().isEmpty() ) {
|
||||
KMessageBox::error( this, i18n("Please put in a name.") );
|
||||
return;
|
||||
}
|
||||
|
||||
Entry *entry = new Entry;
|
||||
|
||||
mEntryList.append( entry );
|
||||
|
||||
entry->setName( mNameEdit->text() );
|
||||
entry->setAuthor( mAuthorEdit->text() );
|
||||
entry->setVersion( mVersionEdit->text() );
|
||||
entry->setRelease( mReleaseSpin->value() );
|
||||
entry->setLicence( mLicenceCombo->currentText() );
|
||||
entry->setPreview( KURL( mPreviewUrl->url().section("/", -1) ), mLanguageCombo->currentText() );
|
||||
entry->setSummary( mSummaryEdit->text(), mLanguageCombo->currentText() );
|
||||
|
||||
TDEConfig *conf = kapp->config();
|
||||
conf->setGroup("KNewStuffUpload");
|
||||
conf->writeEntry("name", mNameEdit->text());
|
||||
conf->writeEntry("author", mAuthorEdit->text());
|
||||
conf->writeEntry("version", mVersionEdit->text());
|
||||
conf->writeEntry("release", mReleaseSpin->value());
|
||||
conf->writeEntry("licence", mLicenceCombo->currentText());
|
||||
conf->writeEntry("preview", mPreviewUrl->url());
|
||||
conf->writeEntry("summary", mSummaryEdit->text());
|
||||
conf->writeEntry("language", mLanguageCombo->currentText());
|
||||
conf->sync();
|
||||
|
||||
mEngine->upload( entry );
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
void UploadDialog::setPreviewFile( const TQString &previewFile )
|
||||
{
|
||||
mPreviewUrl->setURL( previewFile );
|
||||
}
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
This file is part of KOrganizer.
|
||||
Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KNEWSTUFF_UPLOADDIALOG_H
|
||||
#define KNEWSTUFF_UPLOADDIALOG_H
|
||||
|
||||
#include <kdialogbase.h>
|
||||
|
||||
class TQLineEdit;
|
||||
class TQSpinBox;
|
||||
class KURLRequester;
|
||||
class TQTextEdit;
|
||||
class TQComboBox;
|
||||
|
||||
namespace KNS {
|
||||
|
||||
class Engine;
|
||||
class Entry;
|
||||
|
||||
/**
|
||||
* @short KNewStuff file upload dialog.
|
||||
*
|
||||
* Using this dialog, data can easily be uploaded to the Hotstuff servers.
|
||||
* It should however not be used on its own, instead a KNewStuff (or
|
||||
* KNewStuffGeneric) object invokes it.
|
||||
*
|
||||
* @author Cornelius Schumacher (schumacher@kde.org)
|
||||
* \par Maintainer:
|
||||
* Josef Spillner (spillner@kde.org)
|
||||
*/
|
||||
class UploadDialog : public KDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
@param engine a KNewStuff engine object to be used for uploads
|
||||
@param parent the parent window
|
||||
*/
|
||||
UploadDialog( Engine *engine, TQWidget *parent );
|
||||
|
||||
/**
|
||||
Destructor.
|
||||
*/
|
||||
~UploadDialog();
|
||||
|
||||
/**
|
||||
Sets the preview filename.
|
||||
This is only meaningful if the application supports previews.
|
||||
|
||||
@param previewFile the preview image file
|
||||
*/
|
||||
void setPreviewFile( const TQString &previewFile );
|
||||
|
||||
protected slots:
|
||||
void slotOk();
|
||||
|
||||
private:
|
||||
Engine *mEngine;
|
||||
|
||||
TQLineEdit *mNameEdit;
|
||||
TQLineEdit *mAuthorEdit;
|
||||
TQLineEdit *mVersionEdit;
|
||||
TQSpinBox *mReleaseSpin;
|
||||
KURLRequester *mPreviewUrl;
|
||||
TQTextEdit *mSummaryEdit;
|
||||
TQComboBox *mLanguageCombo;
|
||||
TQComboBox *mLicenceCombo;
|
||||
|
||||
TQPtrList<Entry> mEntryList;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in new issue