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 <tqcombobox.h> 00022 #include <tqlabel.h> 00023 #include <tqlayout.h> 00024 #include <tqlineedit.h> 00025 #include <tqspinbox.h> 00026 #include <tqstring.h> 00027 #include <ktextedit.h> 00028 00029 #include <tdelistview.h> 00030 #include <tdelocale.h> 00031 #include <kdebug.h> 00032 #include <kurlrequester.h> 00033 #include <tdemessagebox.h> 00034 #include <tdeconfig.h> 00035 #include <tdeapplication.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, TQWidget *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 TQFrame *topPage = plainPage(); 00054 00055 TQGridLayout *topLayout = new TQGridLayout( topPage ); 00056 topLayout->setSpacing( spacingHint() ); 00057 00058 TQLabel *nameLabel = new TQLabel( i18n("Name:"), topPage ); 00059 topLayout->addWidget( nameLabel, 0, 0 ); 00060 mNameEdit = new TQLineEdit( topPage ); 00061 topLayout->addWidget( mNameEdit, 0, 1 ); 00062 00063 TQLabel *authorLabel = new TQLabel( i18n("Author:"), topPage ); 00064 topLayout->addWidget( authorLabel, 1, 0 ); 00065 mAuthorEdit = new TQLineEdit( topPage ); 00066 topLayout->addWidget( mAuthorEdit, 1, 1 ); 00067 00068 TQLabel *emailLabel = new TQLabel( i18n("Email:"), topPage ); 00069 topLayout->addWidget( emailLabel, 2, 0 ); 00070 mEmailEdit = new TQLineEdit( topPage ); 00071 topLayout->addWidget( mEmailEdit, 2, 1 ); 00072 00073 TQLabel *versionLabel = new TQLabel( i18n("Version:"), topPage ); 00074 topLayout->addWidget( versionLabel, 3, 0 ); 00075 mVersionEdit = new TQLineEdit( topPage ); 00076 topLayout->addWidget( mVersionEdit, 3, 1 ); 00077 00078 TQLabel *releaseLabel = new TQLabel( i18n("Release:"), topPage ); 00079 topLayout->addWidget( releaseLabel, 4, 0 ); 00080 mReleaseSpin = new TQSpinBox( topPage ); 00081 mReleaseSpin->setMinValue( 1 ); 00082 topLayout->addWidget( mReleaseSpin, 4, 1 ); 00083 00084 TQLabel *licenceLabel = new TQLabel( i18n("License:"), topPage ); 00085 topLayout->addWidget( licenceLabel, 5, 0 ); 00086 mLicenceCombo = new TQComboBox( 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 TQLabel *languageLabel = new TQLabel( i18n("Language:"), topPage ); 00094 topLayout->addWidget( languageLabel, 6, 0 ); 00095 mLanguageCombo = new TQComboBox( topPage ); 00096 topLayout->addWidget( mLanguageCombo, 6, 1 ); 00097 mLanguageCombo->insertStringList( TDEGlobal::locale()->languageList() ); 00098 00099 TQLabel *previewLabel = new TQLabel( i18n("Preview URL:"), topPage ); 00100 topLayout->addWidget( previewLabel, 7, 0 ); 00101 mPreviewUrl = new KURLRequester( topPage ); 00102 topLayout->addWidget( mPreviewUrl, 7, 1 ); 00103 00104 TQLabel *summaryLabel = new TQLabel( 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 TDEConfig *conf = kapp->config(); 00140 conf->setGroup( TQString("TDENewStuffUpload:%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 TQString &previewFile ) 00159 { 00160 mPreviewUrl->setURL( previewFile ); 00161 } 00162 00163 void UploadDialog::setPayloadFile( const TQString &payloadFile ) 00164 { 00165 mPayloadUrl = payloadFile; 00166 00167 TDEConfig *conf = kapp->config(); 00168 conf->setGroup( TQString("TDENewStuffUpload:%1").arg(mPayloadUrl.fileName()) ); 00169 TQString name = conf->readEntry("name"); 00170 TQString author = conf->readEntry("author"); 00171 TQString email = conf->readEntry("email"); 00172 TQString version = conf->readEntry("version"); 00173 TQString release = conf->readEntry("release"); 00174 TQString preview = conf->readEntry("preview"); 00175 TQString summary = conf->readEntry("summary"); 00176 TQString lang = conf->readEntry("language"); 00177 TQString 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?"),TQString::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