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 00026 #include <kaboutdata.h> 00027 #include <kcombobox.h> 00028 #include <kcomponentdata.h> 00029 #include <kconfig.h> 00030 #include <kglobal.h> 00031 #include <klineedit.h> 00032 #include <klocale.h> 00033 #include <kmessagebox.h> 00034 #include <ktextedit.h> 00035 #include <kurlrequester.h> 00036 #include <kuser.h> 00037 00038 #include <kdebug.h> 00039 00040 //#include "engine.h" 00041 #include "knewstuff2/core/entry.h" 00042 #include "knewstuff2/core/author.h" 00043 00044 #include <kconfiggroup.h> 00045 00046 using namespace KNS; 00047 00048 UploadDialog::UploadDialog(/*Engine *engine,*/ QWidget *parent) : 00049 KDialog(parent) 00050 { 00051 m_entry = NULL; 00052 00053 // popuplate dialog with stuff 00054 QWidget* _mainWidget = new QWidget(this); 00055 setMainWidget(_mainWidget); 00056 setupUi(_mainWidget); 00057 00058 setCaption(i18n("Share Hot New Stuff")); 00059 setButtons(Ok | Cancel); 00060 setDefaultButton(Cancel); 00061 setModal(false); 00062 00063 mTitleWidget->setText(i18nc("Program name followed by 'Add On Uploader'", 00064 "%1 Add-On Uploader", 00065 KGlobal::activeComponent().aboutData()->programName())); 00066 mTitleWidget->setPixmap(KIcon(KGlobal::activeComponent().aboutData()->programIconName())); 00067 00068 QStringList languagecodes = KGlobal::locale()->languageList(); 00069 for (int i = 0; i < languagecodes.count(); i++) { 00070 QString languagecode = languagecodes.at(i); 00071 QString language = KGlobal::locale()->languageCodeToName(languagecode); 00072 mLanguageCombo->addItem(language); 00073 m_languages.insert(language, languagecode); 00074 } 00075 00076 KUser user; 00077 mAuthorEdit->setText(user.property(KUser::FullName).toString()); 00078 00079 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); 00080 } 00081 00082 UploadDialog::~UploadDialog() 00083 { 00084 //qDeleteAll(mEntryList); 00085 //mEntryList.clear(); 00086 } 00087 00088 void UploadDialog::slotOk() 00089 { 00090 if (mNameEdit->text().isEmpty()) { 00091 KMessageBox::error(this, i18n("Please put in a name.")); 00092 //return; 00093 reject(); // FIXME - huh? return should work here but it accept()s! 00094 } 00095 00096 QString language = m_languages.value(mLanguageCombo->currentText()); 00097 00098 Author author; 00099 author.setName(mAuthorEdit->text()); 00100 author.setEmail(mEmailEdit->text()); 00101 00102 KTranslatable previewurl; 00103 KUrl purl = mPreviewUrl->url(); 00104 //purl.setFileName(QString()); 00105 // FIXME: what does this do? 00106 previewurl.addString(language, purl.url()); 00107 00108 KTranslatable summary; 00109 summary.addString(language, mSummaryEdit->toPlainText()); 00110 00111 KTranslatable name; 00112 name.addString(language, mNameEdit->text()); 00113 00114 m_entry = new Entry; 00115 m_entry->setName(name); 00116 m_entry->setAuthor(author); 00117 m_entry->setVersion(mVersionEdit->text()); 00118 m_entry->setLicense(mLicenseCombo->currentText()); 00119 m_entry->setPreview(previewurl); 00120 m_entry->setSummary(summary); 00121 00122 if (mPayloadUrl.isValid()) { 00123 KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName())); 00124 cg.writeEntry("name", mNameEdit->text()); 00125 cg.writeEntry("author", mAuthorEdit->text()); 00126 cg.writeEntry("author-email", mEmailEdit->text()); 00127 cg.writeEntry("version", mVersionEdit->text()); 00128 cg.writeEntry("license", mLicenseCombo->currentText()); 00129 cg.writeEntry("preview", mPreviewUrl->url().url()); 00130 cg.writeEntry("summary", mSummaryEdit->toPlainText()); 00131 cg.writeEntry("language", mLanguageCombo->currentText()); 00132 KGlobal::config()->sync(); 00133 } 00134 00135 accept(); 00136 } 00137 00138 void UploadDialog::setPreviewFile(const KUrl& previewFile) 00139 { 00140 mPreviewUrl->setUrl(previewFile); 00141 } 00142 00143 void UploadDialog::setPayloadFile(const KUrl& payloadFile) 00144 { 00145 mPayloadUrl = payloadFile; 00146 00147 KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName())); 00148 QString name = cg.readEntry("name"); 00149 QString author = cg.readEntry("author"); 00150 QString email = cg.readEntry("author-email"); 00151 QString version = cg.readEntry("version"); 00152 KUrl preview(cg.readEntry("preview")); 00153 QString summary = cg.readEntry("summary"); 00154 QString lang = cg.readEntry("language"); 00155 QString license = cg.readEntry("license"); 00156 00157 if (!name.isNull()) { 00158 int prefill = KMessageBox::questionYesNo(this, 00159 i18n("Old upload information found, fill out fields?"), 00160 QString(), 00161 KGuiItem(i18n("Fill Out")), 00162 KGuiItem(i18n("Do Not Fill Out"))); 00163 if (prefill == KMessageBox::Yes) { 00164 mNameEdit->setText(name); 00165 mAuthorEdit->setText(author); 00166 mEmailEdit->setText(email); 00167 mVersionEdit->setText(version); 00168 //mReleaseSpin->setValue(release.toInt()); 00169 mPreviewUrl->setUrl(preview); 00170 mSummaryEdit->setPlainText(summary); 00171 if (!lang.isEmpty()) mLanguageCombo->setCurrentIndex(mLanguageCombo->findText(lang)); 00172 if (!license.isEmpty()) mLicenseCombo->setCurrentIndex(mLicenseCombo->findText(license)); 00173 } 00174 } 00175 } 00176 00177 Entry *UploadDialog::entry() const 00178 { 00179 return m_entry; 00180 } 00181 00182 #include "uploaddialog.moc"
KDE 4.6 API Reference