32 #include <qeventloop.h>
36 class KNS::EnginePrivate :
public DxsEngine
43 m_command = EnginePrivate::command_none;
44 m_uploaddialog = NULL;
45 m_downloaddialog = NULL;
46 m_uploadedEntry = NULL;
75 void slotDownloadDialogDestroyed();
87 void slotHandleUpload();
88 void slotEntriesFinished();
90 void slotDownloadDialogClosed();
97 : d(new EnginePrivate(parent))
104 if (d->m_downloaddialog) {
105 d->slotDownloadDialogDestroyed();
111 void EnginePrivate::workflow()
113 disconnect(
this, 0,
this, 0);
114 if ((m_command == command_upload) || (m_command == command_download)) {
120 if (m_command == command_upload) {
122 SIGNAL(signalProvidersFinished()),
123 SLOT(slotHandleUpload()));
125 SIGNAL(signalProvidersFailed()),
128 m_uploadedEntry = NULL;
131 if (m_command == command_download) {
134 s_dialogs.insert(componentName(), m_downloaddialog);
136 connect(
this, SIGNAL(signalEntriesFinished()),
137 SLOT(slotEntriesFinished()));
142 SIGNAL(signalProvidersFailed()),
143 SLOT(slotDownloadDialogClosed()));
144 connect(m_downloaddialog,
146 SLOT(slotDownloadDialogDestroyed()));
147 connect(m_downloaddialog, SIGNAL(finished()), SLOT(slotDownloadDialogClosed()));
150 m_downloaddialog->show();
162 void EnginePrivate::stopLoop()
164 m_command = command_none;
170 if (m_downloaddialog) {
171 slotDownloadDialogDestroyed();
185 bool ret = engine->
init(name +
".knsrc");
194 foreach(
Entry * entry, tempList) {
195 entries <<
new Entry(*entry);
205 KDialog *existingDialog = EnginePrivate::s_dialogs.value(d->componentName());
206 if (existingDialog) {
207 existingDialog->show();
213 d->m_command = EnginePrivate::command_download;
216 d->m_parent = parent;
227 KDialog *existingDialog = EnginePrivate::s_dialogs.value(d->componentName());
228 if (existingDialog) {
230 existingDialog->show();
236 if (d->m_command != EnginePrivate::command_none) {
237 kError() <<
"Engine: asynchronous workflow already going on" << endl;
241 d->m_command = EnginePrivate::command_download;
249 QObject::disconnect(d, SIGNAL(signalDownloadDialogDone(
KNS::Entry::List)), receiver, slot);
250 QObject::connect(d, SIGNAL(signalDownloadDialogDone(
KNS::Entry::List)), receiver, slot);
263 bool ret = engine.init(name +
".knsrc");
264 if (!ret)
return entry;
266 entry = engine.uploadDialogModal(file);
274 return d->init(config);
281 #warning KNS::Engine::upload() not implemented!
284 return d->upload(file);
296 d->m_command = EnginePrivate::command_upload;
298 d->m_uploadfile = file;
302 return d->m_uploadedEntry;
309 if (d->m_command != EnginePrivate::command_none) {
310 kError() <<
"Engine: asynchronous workflow already going on" << endl;
314 d->m_command = EnginePrivate::command_upload;
316 d->m_uploadfile = file;
321 void EnginePrivate::slotProviderLoaded(
KNS::Provider *provider)
323 if (m_command == command_download) {
324 loadEntries(provider);
325 }
else if (m_command == command_upload) {
331 m_providers.append(provider);
333 kError() <<
"Engine: invalid command" << endl;
337 void EnginePrivate::slotHandleUpload()
350 for (Provider::List::Iterator it = m_providers.begin(); it != m_providers.end(); ++it) {
352 provdialog->addProvider(provider);
355 if (provdialog->exec() == QDialog::Rejected) {
363 QPointer<UploadDialog> uploaddialog =
new UploadDialog(NULL);
364 uploaddialog->setPayloadFile(
KUrl(m_uploadfile));
365 if (uploaddialog->exec() == QDialog::Rejected) {
370 Entry *entry = uploaddialog->entry();
379 for (QStringList::const_iterator it = langs.constBegin(); it != langs.constEnd(); ++it) {
385 QDomElement xml = eh.entryXML();
387 QTextStream txt(&ar);
391 connect(
this, SIGNAL(signalEntryUploaded()), SLOT(stopLoop()));
392 connect(
this, SIGNAL(signalEntryFailed()), SLOT(stopLoop()));
394 uploadEntry(provider, entry);
395 m_uploadedEntry=entry;
398 void EnginePrivate::slotEntryChanged(
KNS::Entry * entry)
401 m_changedEntries << entry;
405 void EnginePrivate::slotEntriesFinished()
410 void EnginePrivate::slotDownloadDialogDestroyed()
414 while (it != s_dialogs.end()) {
415 if (it.value() == m_downloaddialog) {
417 it = s_dialogs.erase(it);
420 if (it != s_dialogs.end()) {
428 void EnginePrivate::slotDownloadDialogClosed()
431 disconnect(m_downloaddialog, SIGNAL(destroyed(
QObject*)),
432 this, SLOT(slotDownloadDialogDestroyed()));
433 slotDownloadDialogDestroyed();
434 m_downloaddialog->deleteLater();
435 m_downloaddialog = NULL;
440 #include "engine.moc"
static KNS::Entry::List download()
Recommended download workflow entry point.
void downloadDialog()
Asynchronous way of starting the download workflow.
KNS::Entry * uploadDialogModal(const QString &file)
Synchronous way of starting the upload workflow.
KNewStuff data entry container.
static void setOnDesktop(WId win, int desktop)
String class with multiple localized representations.
void addString(const QString &lang, const QString &string)
Adds a string to the contents of this object.
const char * name(StandardAction id)
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
bool init(const QString &config)
KNewStuff file upload dialog.
void uploadDialog(const QString &file)
Asynchronous way of starting the upload workflow.
KTranslatable name() const
Retrieve the name of the data object.
static void activateWindow(WId win, long time=0)
static int currentDesktop()
Engine(QWidget *parent=0)
Engine constructor.
KComponentData activeComponent()
QString componentName() const
~Engine()
Engine destructor.
QStringList languages() const
Returns the list of all languages for which strings are stored.
Dialog displaying a list of Hotstuff providers.
KNS::Entry::List downloadDialogModal(QWidget *parent=0)
Synchronous way of starting the download workflow.
void setPayload(const KTranslatable &url)
Sets the object's file.
static KNS::Entry * upload(const QString &file)
Recommended upload workflow entry point.
The KNewStuff2 engine is the top-level class to handle GHNS and DXS workflows.
Parser and dumper for KNewStuff data entries.
KNewStuff provider container.
KNewStuff download dialog.