• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff2
  • ui
knewstuff2/ui/uploaddialog.cpp
Go to the documentation of this file.
1/*
2 This file is part of KNewStuff2.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include "uploaddialog.h"
20
21#include <QtGui/QLabel>
22#include <QtGui/QLayout>
23#include <QtGui/QDoubleSpinBox>
24#include <QtCore/QString>
25
26#include <kaboutdata.h>
27#include <kcombobox.h>
28#include <kcomponentdata.h>
29#include <kconfig.h>
30#include <kglobal.h>
31#include <klineedit.h>
32#include <klocale.h>
33#include <kmessagebox.h>
34#include <ktextedit.h>
35#include <kurlrequester.h>
36#include <kuser.h>
37
38#include <kdebug.h>
39
40//#include "engine.h"
41#include "knewstuff2/core/entry.h"
42#include "knewstuff2/core/author.h"
43
44#include <kconfiggroup.h>
45
46using namespace KNS;
47
48UploadDialog::UploadDialog(/*Engine *engine,*/ QWidget *parent) :
49 KDialog(parent)
50{
51 m_entry = NULL;
52
53 // popuplate dialog with stuff
54 QWidget* _mainWidget = new QWidget(this);
55 setMainWidget(_mainWidget);
56 setupUi(_mainWidget);
57
58 setCaption(i18n("Share Hot New Stuff"));
59 setButtons(Ok | Cancel);
60 setDefaultButton(Cancel);
61 setModal(false);
62
63 mTitleWidget->setText(i18nc("Program name followed by 'Add On Uploader'",
64 "%1 Add-On Uploader",
65 KGlobal::activeComponent().aboutData()->programName()));
66 mTitleWidget->setPixmap(KIcon(KGlobal::activeComponent().aboutData()->programIconName()));
67
68 QStringList languagecodes = KGlobal::locale()->languageList();
69 for (int i = 0; i < languagecodes.count(); i++) {
70 QString languagecode = languagecodes.at(i);
71 QString language = KGlobal::locale()->languageCodeToName(languagecode);
72 mLanguageCombo->addItem(language);
73 m_languages.insert(language, languagecode);
74 }
75
76 KUser user;
77 mAuthorEdit->setText(user.property(KUser::FullName).toString());
78
79 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
80}
81
82UploadDialog::~UploadDialog()
83{
84//qDeleteAll(mEntryList);
85//mEntryList.clear();
86}
87
88void UploadDialog::slotOk()
89{
90 if (mNameEdit->text().isEmpty()) {
91 KMessageBox::error(this, i18n("Please put in a name."));
92 //return;
93 reject(); // FIXME - huh? return should work here but it accept()s!
94 }
95
96 QString language = m_languages.value(mLanguageCombo->currentText());
97
98 Author author;
99 author.setName(mAuthorEdit->text());
100 author.setEmail(mEmailEdit->text());
101
102 KTranslatable previewurl;
103 KUrl purl = mPreviewUrl->url();
104 //purl.setFileName(QString());
105 // FIXME: what does this do?
106 previewurl.addString(language, purl.url());
107
108 KTranslatable summary;
109 summary.addString(language, mSummaryEdit->toPlainText());
110
111 KTranslatable name;
112 name.addString(language, mNameEdit->text());
113
114 m_entry = new Entry;
115 m_entry->setName(name);
116 m_entry->setAuthor(author);
117 m_entry->setVersion(mVersionEdit->text());
118 m_entry->setLicense(mLicenseCombo->currentText());
119 m_entry->setPreview(previewurl);
120 m_entry->setSummary(summary);
121
122 if (mPayloadUrl.isValid()) {
123 KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
124 cg.writeEntry("name", mNameEdit->text());
125 cg.writeEntry("author", mAuthorEdit->text());
126 cg.writeEntry("author-email", mEmailEdit->text());
127 cg.writeEntry("version", mVersionEdit->text());
128 cg.writeEntry("license", mLicenseCombo->currentText());
129 cg.writeEntry("preview", mPreviewUrl->url().url());
130 cg.writeEntry("summary", mSummaryEdit->toPlainText());
131 cg.writeEntry("language", mLanguageCombo->currentText());
132 KGlobal::config()->sync();
133 }
134
135 accept();
136}
137
138void UploadDialog::setPreviewFile(const KUrl& previewFile)
139{
140 mPreviewUrl->setUrl(previewFile);
141}
142
143void UploadDialog::setPayloadFile(const KUrl& payloadFile)
144{
145 mPayloadUrl = payloadFile;
146
147 KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
148 QString name = cg.readEntry("name");
149 QString author = cg.readEntry("author");
150 QString email = cg.readEntry("author-email");
151 QString version = cg.readEntry("version");
152 KUrl preview(cg.readEntry("preview"));
153 QString summary = cg.readEntry("summary");
154 QString lang = cg.readEntry("language");
155 QString license = cg.readEntry("license");
156
157 if (!name.isNull()) {
158 int prefill = KMessageBox::questionYesNo(this,
159 i18n("Old upload information found, fill out fields?"),
160 QString(),
161 KGuiItem(i18n("Fill Out")),
162 KGuiItem(i18n("Do Not Fill Out")));
163 if (prefill == KMessageBox::Yes) {
164 mNameEdit->setText(name);
165 mAuthorEdit->setText(author);
166 mEmailEdit->setText(email);
167 mVersionEdit->setText(version);
168 //mReleaseSpin->setValue(release.toInt());
169 mPreviewUrl->setUrl(preview);
170 mSummaryEdit->setPlainText(summary);
171 if (!lang.isEmpty()) mLanguageCombo->setCurrentIndex(mLanguageCombo->findText(lang));
172 if (!license.isEmpty()) mLicenseCombo->setCurrentIndex(mLicenseCombo->findText(license));
173 }
174 }
175}
176
177Entry *UploadDialog::entry() const
178{
179 return m_entry;
180}
181
182#include "uploaddialog.moc"
KConfigGroup
KConfigGroup::writeEntry
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
KConfigGroup::readEntry
QString readEntry(const char *key, const char *aDefault=0) const
KDialog
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
KDialog::Ok
Ok
KDialog::Cancel
Cancel
KDialog::okClicked
void okClicked()
KDialog::setDefaultButton
void setDefaultButton(ButtonCode id)
KDialog::setCaption
virtual void setCaption(const QString &caption)
KGuiItem
KIcon
KLocale::languageCodeToName
QString languageCodeToName(const QString &language) const
KLocale::languageList
QStringList languageList() const
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KMessageBox::Yes
Yes
KMessageBox::questionYesNo
static int questionYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Notify)
KNS::Author
KNewStuff author information.
Definition: knewstuff2/core/author.h:41
KNS::Author::setName
void setName(const QString &name)
Sets the full name of the author.
Definition: knewstuff2/core/author.cpp:53
KNS::Author::setEmail
void setEmail(const QString &email)
Sets the email address of the author.
Definition: knewstuff2/core/author.cpp:63
KNS::Entry
KNewStuff data entry container.
Definition: knewstuff2/core/entry.h:47
KNS::Entry::setLicense
void setLicense(const QString &license)
Sets the license (abbreviation) applicable to the object.
Definition: knewstuff2/core/entry.cpp:106
KNS::Entry::setVersion
void setVersion(const QString &version)
Sets the version number.
Definition: knewstuff2/core/entry.cpp:126
KNS::Entry::setAuthor
void setAuthor(const Author &author)
Sets the author of the object.
Definition: knewstuff2/core/entry.cpp:96
KNS::Entry::setPreview
void setPreview(const KTranslatable &url)
Sets the object's preview file, if available.
Definition: knewstuff2/core/entry.cpp:166
KNS::Entry::setSummary
void setSummary(const KTranslatable &summary)
Sets a short description on what the object is all about.
Definition: knewstuff2/core/entry.cpp:116
KNS::Entry::setName
void setName(const KTranslatable &name)
Sets the name for this data object.
Definition: knewstuff2/core/entry.cpp:76
KNS::KTranslatable
String class with multiple localized representations.
Definition: ktranslatable.h:42
KNS::KTranslatable::addString
void addString(const QString &lang, const QString &string)
Adds a string to the contents of this object.
Definition: ktranslatable.cpp:59
KNS::UploadDialog::setPayloadFile
void setPayloadFile(const KUrl &payloadFile)
Sets the payload filename.
Definition: knewstuff2/ui/uploaddialog.cpp:143
KNS::UploadDialog::~UploadDialog
~UploadDialog()
Destructor.
Definition: knewstuff2/ui/uploaddialog.cpp:82
KNS::UploadDialog::UploadDialog
UploadDialog(QWidget *parent)
Constructor.
Definition: knewstuff2/ui/uploaddialog.cpp:48
KNS::UploadDialog::setPreviewFile
void setPreviewFile(const KUrl &previewFile)
Sets the preview filename.
Definition: knewstuff2/ui/uploaddialog.cpp:138
KNS::UploadDialog::slotOk
void slotOk()
Definition: knewstuff2/ui/uploaddialog.cpp:88
KNS::UploadDialog::entry
Entry * entry() const
Definition: knewstuff2/ui/uploaddialog.cpp:177
KUrl
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
KUser
KUser::property
QVariant property(UserProperty which) const
KUser::FullName
FullName
QWidget
kaboutdata.h
kcombobox.h
kcomponentdata.h
kconfig.h
kconfiggroup.h
kdebug.h
kglobal.h
klineedit.h
klocale.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
kmessagebox.h
author.h
entry.h
uploaddialog.h
ktextedit.h
kurlrequester.h
kuser.h
KGlobal::locale
KLocale * locale()
KGlobal::config
KSharedConfigPtr config()
KGlobal::activeComponent
KComponentData activeComponent()
KNS
Definition: knewstuff2/core/author.h:27
name
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal