uploaddialog.cpp

00001 /*
00002     This file is part of KOrganizer.
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 Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 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     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
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 *versionLabel = new QLabel( i18n("Version:"), topPage );
00069   topLayout->addWidget( versionLabel, 2, 0 );  
00070   mVersionEdit = new QLineEdit( topPage );
00071   topLayout->addWidget( mVersionEdit, 2, 1 );
00072 
00073   QLabel *releaseLabel = new QLabel( i18n("Release:"), topPage );
00074   topLayout->addWidget( releaseLabel, 3, 0 );  
00075   mReleaseSpin = new QSpinBox( topPage );
00076   mReleaseSpin->setMinValue( 1 );
00077   topLayout->addWidget( mReleaseSpin, 3, 1 );
00078 
00079   QLabel *licenceLabel = new QLabel( i18n("License:"), topPage );
00080   topLayout->addWidget( licenceLabel, 4, 0 );
00081   mLicenceCombo = new QComboBox( topPage );
00082   mLicenceCombo->setEditable( true );
00083   mLicenceCombo->insertItem( i18n("GPL") );
00084   mLicenceCombo->insertItem( i18n("LGPL") );
00085   mLicenceCombo->insertItem( i18n("BSD") );
00086   topLayout->addWidget( mLicenceCombo, 4, 1 );
00087 
00088   QLabel *languageLabel = new QLabel( i18n("Language:"), topPage );
00089   topLayout->addWidget( languageLabel, 5, 0 );
00090   mLanguageCombo = new QComboBox( topPage );
00091   topLayout->addWidget( mLanguageCombo, 5, 1 );
00092   mLanguageCombo->insertStringList( KGlobal::locale()->languageList() );
00093 
00094   QLabel *previewLabel = new QLabel( i18n("Preview URL:"), topPage );
00095   topLayout->addWidget( previewLabel, 6, 0 );
00096   mPreviewUrl = new KURLRequester( topPage );
00097   topLayout->addWidget( mPreviewUrl, 6, 1 );
00098 
00099   QLabel *summaryLabel = new QLabel( i18n("Summary:"), topPage );
00100   topLayout->addMultiCellWidget( summaryLabel, 7, 7, 0, 1 );
00101   mSummaryEdit = new KTextEdit( topPage );
00102   topLayout->addMultiCellWidget( mSummaryEdit, 8, 8, 0, 1 );
00103 
00104   KUser user;
00105   mAuthorEdit->setText(user.fullName());
00106 }
00107 
00108 UploadDialog::~UploadDialog()
00109 {
00110   mEntryList.clear();
00111 }
00112 
00113 void UploadDialog::slotOk()
00114 {
00115   if ( mNameEdit->text().isEmpty() ) {
00116     KMessageBox::error( this, i18n("Please put in a name.") );
00117     return;
00118   }
00119 
00120   Entry *entry = new Entry;
00121 
00122   mEntryList.append( entry );
00123 
00124   entry->setName( mNameEdit->text() );
00125   entry->setAuthor( mAuthorEdit->text() );
00126   entry->setVersion( mVersionEdit->text() );
00127   entry->setRelease( mReleaseSpin->value() );
00128   entry->setLicence( mLicenceCombo->currentText() );
00129   entry->setPreview( KURL( mPreviewUrl->url().section("/", -1) ), mLanguageCombo->currentText() );
00130   entry->setSummary( mSummaryEdit->text(), mLanguageCombo->currentText() );
00131 
00132   if ( mPayloadUrl.isValid() ) {
00133     KConfig *conf = kapp->config();
00134     conf->setGroup( QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()) );
00135     conf->writeEntry("name", mNameEdit->text());
00136     conf->writeEntry("author", mAuthorEdit->text());
00137     conf->writeEntry("version", mVersionEdit->text());
00138     conf->writeEntry("release", mReleaseSpin->value());
00139     conf->writeEntry("licence", mLicenceCombo->currentText());
00140     conf->writeEntry("preview", mPreviewUrl->url());
00141     conf->writeEntry("summary", mSummaryEdit->text());
00142     conf->writeEntry("language", mLanguageCombo->currentText());
00143     conf->sync();
00144   }
00145 
00146   mEngine->upload( entry );
00147 
00148   accept();
00149 }
00150 
00151 void UploadDialog::setPreviewFile( const QString &previewFile )
00152 {
00153   mPreviewUrl->setURL( previewFile );
00154 }
00155 
00156 void UploadDialog::setPayloadFile( const QString &payloadFile )
00157 {
00158   mPayloadUrl = payloadFile;
00159 
00160   KConfig *conf = kapp->config();
00161   conf->setGroup( QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()) );
00162   QString name = conf->readEntry("name");
00163   QString author = conf->readEntry("author");
00164   QString version = conf->readEntry("version");
00165   QString release = conf->readEntry("release");
00166   QString preview = conf->readEntry("preview");
00167   QString summary = conf->readEntry("summary");
00168   QString lang = conf->readEntry("language");
00169   QString licence = conf->readEntry("licence");
00170 
00171   if(!name.isNull())
00172   {
00173     int prefill = KMessageBox::questionYesNo(this, i18n("Old upload information found, fill out fields?"),QString::null,i18n("Fill Out"),i18n("Do Not Fill Out"));
00174     if(prefill == KMessageBox::Yes)
00175     {
00176       mNameEdit->setText(name);
00177       mAuthorEdit->setText(author);
00178       mVersionEdit->setText(version);
00179       mReleaseSpin->setValue(release.toInt());
00180       mPreviewUrl->setURL(preview);
00181       mSummaryEdit->setText(summary);
00182       if(!lang.isEmpty()) mLanguageCombo->setCurrentText(lang);
00183       if(!licence.isEmpty()) mLicenceCombo->setCurrentText(licence);
00184     }
00185   }
00186 }
00187 
KDE Home | KDE Accessibility Home | Description of Access Keys