knewstuff Library API Documentation

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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, 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 00037 #include "engine.h" 00038 #include "entry.h" 00039 00040 #include "uploaddialog.h" 00041 #include "uploaddialog.moc" 00042 00043 using namespace KNS; 00044 00045 UploadDialog::UploadDialog( Engine *engine, QWidget *parent ) : 00046 KDialogBase( Plain, i18n("Share Hot New Stuff"), Ok | Cancel, Cancel, 00047 parent, 0, false, true ), 00048 mEngine( engine ) 00049 { 00050 mEntryList.setAutoDelete( true ); 00051 00052 QFrame *topPage = plainPage(); 00053 00054 QGridLayout *topLayout = new QGridLayout( topPage ); 00055 topLayout->setSpacing( spacingHint() ); 00056 00057 QLabel *nameLabel = new QLabel( i18n("Name:"), topPage ); 00058 topLayout->addWidget( nameLabel, 0, 0 ); 00059 mNameEdit = new QLineEdit( topPage ); 00060 topLayout->addWidget( mNameEdit, 0, 1 ); 00061 00062 QLabel *authorLabel = new QLabel( i18n("Author:"), topPage ); 00063 topLayout->addWidget( authorLabel, 1, 0 ); 00064 mAuthorEdit = new QLineEdit( topPage ); 00065 topLayout->addWidget( mAuthorEdit, 1, 1 ); 00066 00067 QLabel *versionLabel = new QLabel( i18n("Version:"), topPage ); 00068 topLayout->addWidget( versionLabel, 2, 0 ); 00069 mVersionEdit = new QLineEdit( topPage ); 00070 topLayout->addWidget( mVersionEdit, 2, 1 ); 00071 00072 QLabel *releaseLabel = new QLabel( i18n("Release:"), topPage ); 00073 topLayout->addWidget( releaseLabel, 3, 0 ); 00074 mReleaseSpin = new QSpinBox( topPage ); 00075 mReleaseSpin->setMinValue( 1 ); 00076 topLayout->addWidget( mReleaseSpin, 3, 1 ); 00077 00078 QLabel *licenceLabel = new QLabel( i18n("License:"), topPage ); 00079 topLayout->addWidget( licenceLabel, 4, 0 ); 00080 mLicenceCombo = new QComboBox( topPage ); 00081 mLicenceCombo->setEditable( true ); 00082 mLicenceCombo->insertItem( i18n("GPL") ); 00083 mLicenceCombo->insertItem( i18n("LGPL") ); 00084 mLicenceCombo->insertItem( i18n("BSD") ); 00085 topLayout->addWidget( mLicenceCombo, 4, 1 ); 00086 00087 QLabel *languageLabel = new QLabel( i18n("Language:"), topPage ); 00088 topLayout->addWidget( languageLabel, 5, 0 ); 00089 mLanguageCombo = new QComboBox( topPage ); 00090 topLayout->addWidget( mLanguageCombo, 5, 1 ); 00091 mLanguageCombo->insertStringList( KGlobal::locale()->languageList() ); 00092 00093 QLabel *previewLabel = new QLabel( i18n("Preview URL:"), topPage ); 00094 topLayout->addWidget( previewLabel, 6, 0 ); 00095 mPreviewUrl = new KURLRequester( topPage ); 00096 topLayout->addWidget( mPreviewUrl, 6, 1 ); 00097 00098 QLabel *summaryLabel = new QLabel( i18n("Summary:"), topPage ); 00099 topLayout->addMultiCellWidget( summaryLabel, 7, 7, 0, 1 ); 00100 mSummaryEdit = new KTextEdit( topPage ); 00101 topLayout->addMultiCellWidget( mSummaryEdit, 8, 8, 0, 1 ); 00102 00103 KConfig *conf = kapp->config(); 00104 conf->setGroup("KNewStuffUpload"); 00105 QString name = conf->readEntry("name"); 00106 QString author = conf->readEntry("author"); 00107 QString version = conf->readEntry("version"); 00108 QString release = conf->readEntry("release"); 00109 QString preview = conf->readEntry("preview"); 00110 QString summary = conf->readEntry("summary"); 00111 QString lang = conf->readEntry("language"); 00112 QString licence = conf->readEntry("licence"); 00113 00114 if(!name.isNull()) 00115 { 00116 int prefill = KMessageBox::questionYesNo(this, i18n("Old upload information found, fill out fields?")); 00117 if(prefill == KMessageBox::Yes) 00118 { 00119 mNameEdit->setText(name); 00120 mAuthorEdit->setText(author); 00121 mVersionEdit->setText(version); 00122 mReleaseSpin->setValue(release.toInt()); 00123 mPreviewUrl->setURL(preview); 00124 mSummaryEdit->setText(summary); 00125 if(!lang.isEmpty()) mLanguageCombo->setCurrentText(lang); 00126 if(!licence.isEmpty()) mLicenceCombo->setCurrentText(licence); 00127 } 00128 } 00129 } 00130 00131 UploadDialog::~UploadDialog() 00132 { 00133 mEntryList.clear(); 00134 } 00135 00136 void UploadDialog::slotOk() 00137 { 00138 if ( mNameEdit->text().isEmpty() ) { 00139 KMessageBox::error( this, i18n("Please put in a name.") ); 00140 return; 00141 } 00142 00143 Entry *entry = new Entry; 00144 00145 mEntryList.append( entry ); 00146 00147 entry->setName( mNameEdit->text() ); 00148 entry->setAuthor( mAuthorEdit->text() ); 00149 entry->setVersion( mVersionEdit->text() ); 00150 entry->setRelease( mReleaseSpin->value() ); 00151 entry->setLicence( mLicenceCombo->currentText() ); 00152 entry->setPreview( KURL( mPreviewUrl->url().section("/", -1) ), mLanguageCombo->currentText() ); 00153 entry->setSummary( mSummaryEdit->text(), mLanguageCombo->currentText() ); 00154 00155 KConfig *conf = kapp->config(); 00156 conf->setGroup("KNewStuffUpload"); 00157 conf->writeEntry("name", mNameEdit->text()); 00158 conf->writeEntry("author", mAuthorEdit->text()); 00159 conf->writeEntry("version", mVersionEdit->text()); 00160 conf->writeEntry("release", mReleaseSpin->value()); 00161 conf->writeEntry("licence", mLicenceCombo->currentText()); 00162 conf->writeEntry("preview", mPreviewUrl->url()); 00163 conf->writeEntry("summary", mSummaryEdit->text()); 00164 conf->writeEntry("language", mLanguageCombo->currentText()); 00165 conf->sync(); 00166 00167 mEngine->upload( entry ); 00168 00169 accept(); 00170 } 00171 00172 void UploadDialog::setPreviewFile( const QString &previewFile ) 00173 { 00174 mPreviewUrl->setURL( previewFile ); 00175 } 00176
KDE Logo
This file is part of the documentation for knewstuff Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Apr 12 23:22:21 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003