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

KNewStuff

  • sources
  • kde-4.14
  • kdelibs
  • 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 
46 using namespace KNS;
47 
48 UploadDialog::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 
82 UploadDialog::~UploadDialog()
83 {
84 //qDeleteAll(mEntryList);
85 //mEntryList.clear();
86 }
87 
88 void 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 
138 void UploadDialog::setPreviewFile(const KUrl& previewFile)
139 {
140  mPreviewUrl->setUrl(previewFile);
141 }
142 
143 void 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 
177 Entry *UploadDialog::entry() const
178 {
179  return m_entry;
180 }
181 
182 #include "uploaddialog.moc"
KNS::UploadDialog::entry
Entry * entry() const
Definition: knewstuff2/ui/uploaddialog.cpp:177
uploaddialog.h
i18n
QString i18n(const char *text)
kcombobox.h
KConfig::sync
void sync()
QWidget
kuser.h
QWidget::setupUi
void setupUi(QWidget *widget)
QDialog::reject
virtual void reject()
QDialog::setModal
void setModal(bool modal)
kdebug.h
KNS::Entry
KNewStuff data entry container.
Definition: knewstuff2/core/entry.h:46
KNS::Author::setEmail
void setEmail(const QString &email)
Sets the email address of the author.
Definition: knewstuff2/core/author.cpp:63
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:41
entry.h
kconfig.h
KUser::property
QVariant property(UserProperty which) const
QList::at
const T & at(int i) const
KNS::KTranslatable::addString
void addString(const QString &lang, const QString &string)
Adds a string to the contents of this object.
Definition: ktranslatable.cpp:59
kurlrequester.h
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KDialog
klocale.h
KLocale::languageCodeToName
QString languageCodeToName(const QString &language) const
KUrl
i18nc
QString i18nc(const char *ctxt, const char *text)
KGlobal::config
KSharedConfigPtr config()
QString::isNull
bool isNull() const
KUser
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
Ok
QObject::name
const char * name() const
kglobal.h
QList::count
int count(const T &value) const
KNS::Author::setName
void setName(const QString &name)
Sets the full name of the author.
Definition: knewstuff2/core/author.cpp:53
KNS::Entry::setAuthor
void setAuthor(const Author &author)
Sets the author of the object.
Definition: knewstuff2/core/entry.cpp:96
author.h
KGuiItem
KNS::Author
KNewStuff author information.
Definition: knewstuff2/core/author.h:40
QString::isEmpty
bool isEmpty() const
KUser::FullName
KIcon
KGlobal::activeComponent
KComponentData activeComponent()
KNS::Entry::setVersion
void setVersion(const QString &version)
Sets the version number.
Definition: knewstuff2/core/entry.cpp:126
KNS::UploadDialog::UploadDialog
UploadDialog(QWidget *parent)
Constructor.
Definition: knewstuff2/ui/uploaddialog.cpp:48
QString
KNS::UploadDialog::~UploadDialog
~UploadDialog()
Destructor.
Definition: knewstuff2/ui/uploaddialog.cpp:82
QDialog::accept
virtual void accept()
QStringList
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)
Cancel
KGlobal::locale
KLocale * locale()
KConfigGroup
KLocale::languageList
QStringList languageList() const
QUrl::isValid
bool isValid() const
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
version
unsigned int version()
ktextedit.h
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
KNS::UploadDialog::setPreviewFile
void setPreviewFile(const KUrl &previewFile)
Sets the preview filename.
Definition: knewstuff2/ui/uploaddialog.cpp:138
QWidget::setCaption
void setCaption(const QString &c)
KNS::UploadDialog::setPayloadFile
void setPayloadFile(const KUrl &payloadFile)
Sets the payload filename.
Definition: knewstuff2/ui/uploaddialog.cpp:143
KNS::Entry::setLicense
void setLicense(const QString &license)
Sets the license (abbreviation) applicable to the object.
Definition: knewstuff2/core/entry.cpp:106
QMap::insert
iterator insert(const Key &key, const T &value)
klineedit.h
KMessageBox::Yes
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
kaboutdata.h
kcomponentdata.h
kmessagebox.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KNS::UploadDialog::slotOk
void slotOk()
Definition: knewstuff2/ui/uploaddialog.cpp:88
QVariant::toString
QString toString() const
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
kconfiggroup.h
KNS::Entry::setPreview
void setPreview(const KTranslatable &url)
Sets the object's preview file, if available.
Definition: knewstuff2/core/entry.cpp:166
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:43 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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