00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qcombobox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qlineedit.h>
00025 #include <qspinbox.h>
00026 #include <qstring.h>
00027 #include <ktextedit.h>
00028
00029 #include <klistview.h>
00030 #include <klocale.h>
00031 #include <kdebug.h>
00032 #include <kurlrequester.h>
00033 #include <kmessagebox.h>
00034 #include <kconfig.h>
00035 #include <kapplication.h>
00036 #include <kuser.h>
00037
00038 #include "engine.h"
00039 #include "entry.h"
00040
00041 #include "uploaddialog.h"
00042 #include "uploaddialog.moc"
00043
00044 using namespace KNS;
00045
00046 UploadDialog::UploadDialog( Engine *engine, QWidget *parent ) :
00047 KDialogBase( Plain, i18n("Share Hot New Stuff"), Ok | Cancel, Cancel,
00048 parent, 0, false, true ),
00049 mEngine( engine )
00050 {
00051 mEntryList.setAutoDelete( true );
00052
00053 QFrame *topPage = plainPage();
00054
00055 QGridLayout *topLayout = new QGridLayout( topPage );
00056 topLayout->setSpacing( spacingHint() );
00057
00058 QLabel *nameLabel = new QLabel( i18n("Name:"), topPage );
00059 topLayout->addWidget( nameLabel, 0, 0 );
00060 mNameEdit = new QLineEdit( topPage );
00061 topLayout->addWidget( mNameEdit, 0, 1 );
00062
00063 QLabel *authorLabel = new QLabel( i18n("Author:"), topPage );
00064 topLayout->addWidget( authorLabel, 1, 0 );
00065 mAuthorEdit = new QLineEdit( topPage );
00066 topLayout->addWidget( mAuthorEdit, 1, 1 );
00067
00068 QLabel *emailLabel = new QLabel( i18n("Email:"), topPage );
00069 topLayout->addWidget( emailLabel, 2, 0 );
00070 mEmailEdit = new QLineEdit( topPage );
00071 topLayout->addWidget( mEmailEdit, 2, 1 );
00072
00073 QLabel *versionLabel = new QLabel( i18n("Version:"), topPage );
00074 topLayout->addWidget( versionLabel, 3, 0 );
00075 mVersionEdit = new QLineEdit( topPage );
00076 topLayout->addWidget( mVersionEdit, 3, 1 );
00077
00078 QLabel *releaseLabel = new QLabel( i18n("Release:"), topPage );
00079 topLayout->addWidget( releaseLabel, 4, 0 );
00080 mReleaseSpin = new QSpinBox( topPage );
00081 mReleaseSpin->setMinValue( 1 );
00082 topLayout->addWidget( mReleaseSpin, 4, 1 );
00083
00084 QLabel *licenceLabel = new QLabel( i18n("License:"), topPage );
00085 topLayout->addWidget( licenceLabel, 5, 0 );
00086 mLicenceCombo = new QComboBox( topPage );
00087 mLicenceCombo->setEditable( true );
00088 mLicenceCombo->insertItem( i18n("GPL") );
00089 mLicenceCombo->insertItem( i18n("LGPL") );
00090 mLicenceCombo->insertItem( i18n("BSD") );
00091 topLayout->addWidget( mLicenceCombo, 5, 1 );
00092
00093 QLabel *languageLabel = new QLabel( i18n("Language:"), topPage );
00094 topLayout->addWidget( languageLabel, 6, 0 );
00095 mLanguageCombo = new QComboBox( topPage );
00096 topLayout->addWidget( mLanguageCombo, 6, 1 );
00097 mLanguageCombo->insertStringList( KGlobal::locale()->languageList() );
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->addMultiCellWidget( summaryLabel, 8, 8, 0, 1 );
00106 mSummaryEdit = new KTextEdit( topPage );
00107 topLayout->addMultiCellWidget( mSummaryEdit, 9, 9, 0, 1 );
00108
00109 KUser user;
00110 mAuthorEdit->setText(user.fullName());
00111 }
00112
00113 UploadDialog::~UploadDialog()
00114 {
00115 mEntryList.clear();
00116 }
00117
00118 void UploadDialog::slotOk()
00119 {
00120 if ( mNameEdit->text().isEmpty() ) {
00121 KMessageBox::error( this, i18n("Please put in a name.") );
00122 return;
00123 }
00124
00125 Entry *entry = new Entry;
00126
00127 mEntryList.append( entry );
00128
00129 entry->setName( mNameEdit->text() );
00130 entry->setAuthor( mAuthorEdit->text() );
00131 entry->setAuthorEmail( mEmailEdit->text() );
00132 entry->setVersion( mVersionEdit->text() );
00133 entry->setRelease( mReleaseSpin->value() );
00134 entry->setLicence( mLicenceCombo->currentText() );
00135 entry->setPreview( KURL( mPreviewUrl->url().section("/", -1) ), mLanguageCombo->currentText() );
00136 entry->setSummary( mSummaryEdit->text(), mLanguageCombo->currentText() );
00137
00138 if ( mPayloadUrl.isValid() ) {
00139 KConfig *conf = kapp->config();
00140 conf->setGroup( QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()) );
00141 conf->writeEntry("name", mNameEdit->text());
00142 conf->writeEntry("author", mAuthorEdit->text());
00143 conf->writeEntry("email", mEmailEdit->text());
00144 conf->writeEntry("version", mVersionEdit->text());
00145 conf->writeEntry("release", mReleaseSpin->value());
00146 conf->writeEntry("licence", mLicenceCombo->currentText());
00147 conf->writeEntry("preview", mPreviewUrl->url());
00148 conf->writeEntry("summary", mSummaryEdit->text());
00149 conf->writeEntry("language", mLanguageCombo->currentText());
00150 conf->sync();
00151 }
00152
00153 mEngine->upload( entry );
00154
00155 accept();
00156 }
00157
00158 void UploadDialog::setPreviewFile( const QString &previewFile )
00159 {
00160 mPreviewUrl->setURL( previewFile );
00161 }
00162
00163 void UploadDialog::setPayloadFile( const QString &payloadFile )
00164 {
00165 mPayloadUrl = payloadFile;
00166
00167 KConfig *conf = kapp->config();
00168 conf->setGroup( QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()) );
00169 QString name = conf->readEntry("name");
00170 QString author = conf->readEntry("author");
00171 QString email = conf->readEntry("email");
00172 QString version = conf->readEntry("version");
00173 QString release = conf->readEntry("release");
00174 QString preview = conf->readEntry("preview");
00175 QString summary = conf->readEntry("summary");
00176 QString lang = conf->readEntry("language");
00177 QString licence = conf->readEntry("licence");
00178
00179 mNameEdit->clear();
00180 mAuthorEdit->clear();
00181 mEmailEdit->clear();
00182 mVersionEdit->clear();
00183 mReleaseSpin->setValue(1);
00184 mPreviewUrl->clear();
00185 mSummaryEdit->clear();
00186 mLanguageCombo->setCurrentItem(0);
00187 mLicenceCombo->setCurrentItem(0);
00188
00189 if(!name.isNull())
00190 {
00191 int prefill = KMessageBox::questionYesNo(this, i18n("Old upload information found, fill out fields?"),QString::null,i18n("Fill Out"),i18n("Do Not Fill Out"));
00192 if(prefill == KMessageBox::Yes)
00193 {
00194 mNameEdit->setText(name);
00195 mAuthorEdit->setText(author);
00196 mEmailEdit->setText(email);
00197 mVersionEdit->setText(version);
00198 mReleaseSpin->setValue(release.toInt());
00199 mPreviewUrl->setURL(preview);
00200 mSummaryEdit->setText(summary);
00201 if(!lang.isEmpty()) mLanguageCombo->setCurrentText(lang);
00202 if(!licence.isEmpty()) mLicenceCombo->setCurrentText(licence);
00203 }
00204 }
00205 }
00206