• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 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 
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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sun Apr 28 2013 14:28:52 by doxygen 1.8.1.1 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.10.2 API Reference

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