00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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( 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 topLayout->setSpacing(spacingHint());
00061
00062 QLabel *sectionselfLabel = new QLabel(i18n("Please give some information about yourself."), topPage);
00063 topLayout->addWidget(sectionselfLabel, 0, 0, 1, 2);
00064
00065 QLabel *authorLabel = new QLabel(i18n("Author:"), topPage);
00066 topLayout->addWidget(authorLabel, 1, 0);
00067 mAuthorEdit = new KLineEdit(topPage);
00068 topLayout->addWidget(mAuthorEdit, 1, 1);
00069
00070 QLabel *emailLabel = new QLabel(i18n("Email address:"), topPage);
00071 topLayout->addWidget(emailLabel, 2, 0);
00072 mEmailEdit = new KLineEdit(topPage);
00073 topLayout->addWidget(mEmailEdit, 2, 1);
00074
00075 QLabel *sectionuploadLabel = new QLabel(i18n("Please describe your upload."), topPage);
00076 topLayout->addWidget(sectionuploadLabel, 3, 0, 1, 2);
00077
00078 QLabel *nameLabel = new QLabel(i18n("Name:"), topPage);
00079 topLayout->addWidget(nameLabel, 4, 0);
00080 mNameEdit = new KLineEdit(topPage);
00081 topLayout->addWidget(mNameEdit, 4, 1);
00082
00083 QLabel *versionLabel = new QLabel(i18n("Version:"), topPage);
00084 topLayout->addWidget(versionLabel, 5, 0);
00085 mVersionEdit = new KLineEdit(topPage);
00086 topLayout->addWidget(mVersionEdit, 5, 1);
00087
00088 QLabel *licenseLabel = new QLabel(i18n("License:"), topPage);
00089 topLayout->addWidget(licenseLabel, 6, 0);
00090 mLicenseCombo = new KComboBox(topPage);
00091 mLicenseCombo->setEditable(true);
00092 mLicenseCombo->addItem(i18n("GPL"));
00093 mLicenseCombo->addItem(i18n("LGPL"));
00094 mLicenseCombo->addItem(i18n("BSD"));
00095 topLayout->addWidget(mLicenseCombo, 6, 1);
00096
00097 QLabel *previewLabel = new QLabel(i18n("Preview URL:"), topPage);
00098 topLayout->addWidget(previewLabel, 7, 0);
00099 mPreviewUrl = new KUrlRequester(topPage);
00100 topLayout->addWidget(mPreviewUrl, 7, 1);
00101
00102 QLabel *summaryLabel = new QLabel(i18n("Summary:"), topPage);
00103 topLayout->addWidget(summaryLabel, 8, 0, 1, 2);
00104 mSummaryEdit = new KTextEdit(topPage);
00105 topLayout->addWidget(mSummaryEdit, 9, 0, 1, 2);
00106
00107 QLabel *sectionlangLabel = new QLabel(i18n("In which language did you describe the above?"), topPage);
00108 topLayout->addWidget(sectionlangLabel, 10, 0, 1, 2);
00109
00110 QLabel *languageLabel = new QLabel(i18n("Language:"), topPage);
00111 topLayout->addWidget(languageLabel, 11, 0);
00112 mLanguageCombo = new KComboBox(topPage);
00113 topLayout->addWidget(mLanguageCombo, 11, 1);
00114
00115 QStringList languagecodes = KGlobal::locale()->languageList();
00116 for (int i = 0; i < languagecodes.count(); i++) {
00117 QString languagecode = languagecodes.at(i);
00118 QString language = KGlobal::locale()->languageCodeToName(languagecode);
00119 mLanguageCombo->addItem(language);
00120 m_languages.insert(language, languagecode);
00121 }
00122
00123 KUser user;
00124 mAuthorEdit->setText(user.property(KUser::FullName).toString());
00125
00126 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
00127 }
00128
00129 UploadDialog::~UploadDialog()
00130 {
00131
00132
00133 }
00134
00135 void UploadDialog::slotOk()
00136 {
00137 if (mNameEdit->text().isEmpty()) {
00138 KMessageBox::error(this, i18n("Please put in a name."));
00139
00140 reject();
00141 }
00142
00143 QString language = m_languages.value(mLanguageCombo->currentText());
00144
00145 Author author;
00146 author.setName(mAuthorEdit->text());
00147 author.setEmail(mEmailEdit->text());
00148
00149 KTranslatable previewurl;
00150 KUrl purl = mPreviewUrl->url();
00151 purl.setFileName(QString());
00152
00153 previewurl.addString(language, purl.url());
00154
00155 KTranslatable summary;
00156 summary.addString(language, mSummaryEdit->toPlainText());
00157
00158 KTranslatable name;
00159 name.addString(language, mNameEdit->text());
00160
00161 m_entry = new Entry;
00162 m_entry->setName(name);
00163 m_entry->setAuthor(author);
00164 m_entry->setVersion(mVersionEdit->text());
00165 m_entry->setLicense(mLicenseCombo->currentText());
00166 m_entry->setPreview(previewurl);
00167 m_entry->setSummary(summary);
00168
00169 if (mPayloadUrl.isValid()) {
00170 KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
00171 cg.writeEntry("name", mNameEdit->text());
00172 cg.writeEntry("author", mAuthorEdit->text());
00173 cg.writeEntry("author-email", mEmailEdit->text());
00174 cg.writeEntry("version", mVersionEdit->text());
00175 cg.writeEntry("license", mLicenseCombo->currentText());
00176 cg.writeEntry("preview", mPreviewUrl->url().url());
00177 cg.writeEntry("summary", mSummaryEdit->toPlainText());
00178 cg.writeEntry("language", mLanguageCombo->currentText());
00179 KGlobal::config()->sync();
00180 }
00181
00182 accept();
00183 }
00184
00185 void UploadDialog::setPreviewFile(const KUrl& previewFile)
00186 {
00187 mPreviewUrl->setUrl(previewFile);
00188 }
00189
00190 void UploadDialog::setPayloadFile(const KUrl& payloadFile)
00191 {
00192 mPayloadUrl = payloadFile;
00193
00194 KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
00195 QString name = cg.readEntry("name");
00196 QString author = cg.readEntry("author");
00197 QString email = cg.readEntry("author-email");
00198 QString version = cg.readEntry("version");
00199 KUrl preview(cg.readEntry("preview"));
00200 QString summary = cg.readEntry("summary");
00201 QString lang = cg.readEntry("language");
00202 QString license = cg.readEntry("license");
00203
00204 if (!name.isNull()) {
00205 int prefill = KMessageBox::questionYesNo(this,
00206 i18n("Old upload information found, fill out fields?"),
00207 QString(),
00208 KGuiItem(i18n("Fill Out")),
00209 KGuiItem(i18n("Do Not Fill Out")));
00210 if (prefill == KMessageBox::Yes) {
00211 mNameEdit->setText(name);
00212 mAuthorEdit->setText(author);
00213 mEmailEdit->setText(email);
00214 mVersionEdit->setText(version);
00215
00216 mPreviewUrl->setUrl(preview);
00217 mSummaryEdit->setPlainText(summary);
00218 if (!lang.isEmpty()) mLanguageCombo->setCurrentIndex(mLanguageCombo->findText(lang));
00219 if (!license.isEmpty()) mLicenseCombo->setCurrentIndex(mLicenseCombo->findText(license));
00220 }
00221 }
00222 }
00223
00224 Entry *UploadDialog::entry() const
00225 {
00226 return m_entry;
00227 }
00228
00229 #include "uploaddialog.moc"