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