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

KNewStuff

uploaddialog.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KNewStuff2.
00003     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 #include "uploaddialog.h"
00020 
00021 #include <QtGui/QLabel>
00022 #include <QtGui/QLayout>
00023 #include <QtGui/QDoubleSpinBox>
00024 #include <QtCore/QString>
00025 #include <ktextedit.h>
00026 
00027 #include <kcombobox.h>
00028 #include <klineedit.h>
00029 #include <klocale.h>
00030 #include <kdebug.h>
00031 #include <kurlrequester.h>
00032 #include <kmessagebox.h>
00033 #include <kconfig.h>
00034 #include <kglobal.h>
00035 #include <kuser.h>
00036 
00037 //#include "engine.h"
00038 #include "knewstuff2/core/entry.h"
00039 #include "knewstuff2/core/author.h"
00040 
00041 #include <kconfiggroup.h>
00042 
00043 using namespace KNS;
00044 
00045 UploadDialog::UploadDialog(/*Engine *engine,*/ QWidget *parent) :
00046         KDialog(parent)
00047 {
00048     m_entry = NULL;
00049 
00050     setCaption(i18n("Share Hot New Stuff"));
00051     setButtons(Ok | Cancel);
00052     setDefaultButton(Cancel);
00053     setModal(false);
00054     showButtonSeparator(true);
00055 
00056     QFrame *topPage = new QFrame(this);
00057     setMainWidget(topPage);
00058 
00059     QGridLayout *topLayout = new QGridLayout(topPage);
00060 
00061     QLabel *sectionselfLabel = new QLabel(i18n("Please give some information about yourself."), topPage);
00062     topLayout->addWidget(sectionselfLabel, 0, 0, 1, 2);
00063 
00064     QLabel *authorLabel = new QLabel(i18n("Author:"), topPage);
00065     topLayout->addWidget(authorLabel, 1, 0);
00066     mAuthorEdit = new KLineEdit(topPage);
00067     topLayout->addWidget(mAuthorEdit, 1, 1);
00068 
00069     QLabel *emailLabel = new QLabel(i18n("Email address:"), topPage);
00070     topLayout->addWidget(emailLabel, 2, 0);
00071     mEmailEdit = new KLineEdit(topPage);
00072     topLayout->addWidget(mEmailEdit, 2, 1);
00073 
00074     QLabel *sectionuploadLabel = new QLabel(i18n("Please describe your upload."), topPage);
00075     topLayout->addWidget(sectionuploadLabel, 3, 0, 1, 2);
00076 
00077     QLabel *nameLabel = new QLabel(i18n("Name:"), topPage);
00078     topLayout->addWidget(nameLabel, 4, 0);
00079     mNameEdit = new KLineEdit(topPage);
00080     topLayout->addWidget(mNameEdit, 4, 1);
00081 
00082     QLabel *versionLabel = new QLabel(i18n("Version:"), topPage);
00083     topLayout->addWidget(versionLabel, 5, 0);
00084     mVersionEdit = new KLineEdit(topPage);
00085     topLayout->addWidget(mVersionEdit, 5, 1);
00086 
00087     QLabel *licenseLabel = new QLabel(i18n("License:"), topPage);
00088     topLayout->addWidget(licenseLabel, 6, 0);
00089     mLicenseCombo = new KComboBox(topPage);
00090     mLicenseCombo->setEditable(true);
00091     mLicenseCombo->addItem(i18n("GPL"));
00092     mLicenseCombo->addItem(i18n("LGPL"));
00093     mLicenseCombo->addItem(i18n("BSD"));
00094     topLayout->addWidget(mLicenseCombo, 6, 1);
00095 
00096     QLabel *previewLabel = new QLabel(i18n("Preview URL:"), topPage);
00097     topLayout->addWidget(previewLabel, 7, 0);
00098     mPreviewUrl = new KUrlRequester(topPage);
00099     topLayout->addWidget(mPreviewUrl, 7, 1);
00100 
00101     QLabel *summaryLabel = new QLabel(i18n("Summary:"), topPage);
00102     topLayout->addWidget(summaryLabel, 8, 0, 1, 2);
00103     mSummaryEdit = new KTextEdit(topPage);
00104     topLayout->addWidget(mSummaryEdit, 9, 0, 1, 2);
00105 
00106     QLabel *sectionlangLabel = new QLabel(i18n("In which language did you describe the above?"), topPage);
00107     topLayout->addWidget(sectionlangLabel, 10, 0, 1, 2);
00108 
00109     QLabel *languageLabel = new QLabel(i18n("Language:"), topPage);
00110     topLayout->addWidget(languageLabel, 11, 0);
00111     mLanguageCombo = new KComboBox(topPage);
00112     topLayout->addWidget(mLanguageCombo, 11, 1);
00113 
00114     QStringList languagecodes = KGlobal::locale()->languageList();
00115     for (int i = 0; i < languagecodes.count(); i++) {
00116         QString languagecode = languagecodes.at(i);
00117         QString language = KGlobal::locale()->languageCodeToName(languagecode);
00118         mLanguageCombo->addItem(language);
00119         m_languages.insert(language, languagecode);
00120     }
00121 
00122     KUser user;
00123     mAuthorEdit->setText(user.property(KUser::FullName).toString());
00124 
00125     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
00126 }
00127 
00128 UploadDialog::~UploadDialog()
00129 {
00130 //qDeleteAll(mEntryList);
00131 //mEntryList.clear();
00132 }
00133 
00134 void UploadDialog::slotOk()
00135 {
00136     if (mNameEdit->text().isEmpty()) {
00137         KMessageBox::error(this, i18n("Please put in a name."));
00138         //return;
00139         reject(); // FIXME - huh? return should work here but it accept()s!
00140     }
00141 
00142     QString language = m_languages.value(mLanguageCombo->currentText());
00143 
00144     Author author;
00145     author.setName(mAuthorEdit->text());
00146     author.setEmail(mEmailEdit->text());
00147 
00148     KTranslatable previewurl;
00149     KUrl purl = mPreviewUrl->url();
00150     purl.setFileName(QString());
00151     // FIXME: what does this do?
00152     previewurl.addString(language, purl.url());
00153 
00154     KTranslatable summary;
00155     summary.addString(language, mSummaryEdit->toPlainText());
00156 
00157     KTranslatable name;
00158     name.addString(language, mNameEdit->text());
00159 
00160     m_entry = new Entry;
00161     m_entry->setName(name);
00162     m_entry->setAuthor(author);
00163     m_entry->setVersion(mVersionEdit->text());
00164     m_entry->setLicense(mLicenseCombo->currentText());
00165     m_entry->setPreview(previewurl);
00166     m_entry->setSummary(summary);
00167 
00168     if (mPayloadUrl.isValid()) {
00169         KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
00170         cg.writeEntry("name", mNameEdit->text());
00171         cg.writeEntry("author", mAuthorEdit->text());
00172         cg.writeEntry("author-email", mEmailEdit->text());
00173         cg.writeEntry("version", mVersionEdit->text());
00174         cg.writeEntry("license", mLicenseCombo->currentText());
00175         cg.writeEntry("preview", mPreviewUrl->url().url());
00176         cg.writeEntry("summary", mSummaryEdit->toPlainText());
00177         cg.writeEntry("language", mLanguageCombo->currentText());
00178         KGlobal::config()->sync();
00179     }
00180 
00181     accept();
00182 }
00183 
00184 void UploadDialog::setPreviewFile(const KUrl& previewFile)
00185 {
00186     mPreviewUrl->setUrl(previewFile);
00187 }
00188 
00189 void UploadDialog::setPayloadFile(const KUrl& payloadFile)
00190 {
00191     mPayloadUrl = payloadFile;
00192 
00193     KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
00194     QString name = cg.readEntry("name");
00195     QString author = cg.readEntry("author");
00196     QString email = cg.readEntry("author-email");
00197     QString version = cg.readEntry("version");
00198     KUrl preview(cg.readEntry("preview"));
00199     QString summary = cg.readEntry("summary");
00200     QString lang = cg.readEntry("language");
00201     QString license = cg.readEntry("license");
00202 
00203     if (!name.isNull()) {
00204         int prefill = KMessageBox::questionYesNo(this,
00205                       i18n("Old upload information found, fill out fields?"),
00206                       QString(),
00207                       KGuiItem(i18n("Fill Out")),
00208                       KGuiItem(i18n("Do Not Fill Out")));
00209         if (prefill == KMessageBox::Yes) {
00210             mNameEdit->setText(name);
00211             mAuthorEdit->setText(author);
00212             mEmailEdit->setText(email);
00213             mVersionEdit->setText(version);
00214             //mReleaseSpin->setValue(release.toInt());
00215             mPreviewUrl->setUrl(preview);
00216             mSummaryEdit->setPlainText(summary);
00217             if (!lang.isEmpty()) mLanguageCombo->setCurrentIndex(mLanguageCombo->findText(lang));
00218             if (!license.isEmpty()) mLicenseCombo->setCurrentIndex(mLicenseCombo->findText(license));
00219         }
00220     }
00221 }
00222 
00223 Entry *UploadDialog::entry() const
00224 {
00225     return m_entry;
00226 }
00227 
00228 #include "uploaddialog.moc"

KNewStuff

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal