TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uploaddialog.cpp 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. This file is part of KOrganizer.
  3. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tqcombobox.h>
  18. #include <tqlabel.h>
  19. #include <tqlayout.h>
  20. #include <tqlineedit.h>
  21. #include <tqspinbox.h>
  22. #include <tqstring.h>
  23. #include <ktextedit.h>
  24. #include <tdelistview.h>
  25. #include <tdelocale.h>
  26. #include <kdebug.h>
  27. #include <kurlrequester.h>
  28. #include <tdemessagebox.h>
  29. #include <tdeconfig.h>
  30. #include <tdeapplication.h>
  31. #include <kuser.h>
  32. #include "engine.h"
  33. #include "entry.h"
  34. #include "uploaddialog.h"
  35. #include "uploaddialog.moc"
  36. using namespace KNS;
  37. UploadDialog::UploadDialog( Engine *engine, TQWidget *parent ) :
  38. KDialogBase( Plain, i18n("Share Hot New Stuff"), Ok | Cancel, Cancel,
  39. parent, 0, false, true ),
  40. mEngine( engine )
  41. {
  42. mEntryList.setAutoDelete( true );
  43. TQFrame *topPage = plainPage();
  44. TQGridLayout *topLayout = new TQGridLayout( topPage );
  45. topLayout->setSpacing( spacingHint() );
  46. TQLabel *nameLabel = new TQLabel( i18n("Name:"), topPage );
  47. topLayout->addWidget( nameLabel, 0, 0 );
  48. mNameEdit = new TQLineEdit( topPage );
  49. topLayout->addWidget( mNameEdit, 0, 1 );
  50. TQLabel *authorLabel = new TQLabel( i18n("Author:"), topPage );
  51. topLayout->addWidget( authorLabel, 1, 0 );
  52. mAuthorEdit = new TQLineEdit( topPage );
  53. topLayout->addWidget( mAuthorEdit, 1, 1 );
  54. TQLabel *emailLabel = new TQLabel( i18n("Email:"), topPage );
  55. topLayout->addWidget( emailLabel, 2, 0 );
  56. mEmailEdit = new TQLineEdit( topPage );
  57. topLayout->addWidget( mEmailEdit, 2, 1 );
  58. TQLabel *versionLabel = new TQLabel( i18n("Version:"), topPage );
  59. topLayout->addWidget( versionLabel, 3, 0 );
  60. mVersionEdit = new TQLineEdit( topPage );
  61. topLayout->addWidget( mVersionEdit, 3, 1 );
  62. TQLabel *releaseLabel = new TQLabel( i18n("Release:"), topPage );
  63. topLayout->addWidget( releaseLabel, 4, 0 );
  64. mReleaseSpin = new TQSpinBox( topPage );
  65. mReleaseSpin->setMinValue( 1 );
  66. topLayout->addWidget( mReleaseSpin, 4, 1 );
  67. TQLabel *licenceLabel = new TQLabel( i18n("License:"), topPage );
  68. topLayout->addWidget( licenceLabel, 5, 0 );
  69. mLicenceCombo = new TQComboBox( topPage );
  70. mLicenceCombo->setEditable( true );
  71. mLicenceCombo->insertItem( i18n("GPL") );
  72. mLicenceCombo->insertItem( i18n("LGPL") );
  73. mLicenceCombo->insertItem( i18n("BSD") );
  74. topLayout->addWidget( mLicenceCombo, 5, 1 );
  75. TQLabel *languageLabel = new TQLabel( i18n("Language:"), topPage );
  76. topLayout->addWidget( languageLabel, 6, 0 );
  77. mLanguageCombo = new TQComboBox( topPage );
  78. topLayout->addWidget( mLanguageCombo, 6, 1 );
  79. mLanguageCombo->insertStringList( TDEGlobal::locale()->languageList() );
  80. TQLabel *previewLabel = new TQLabel( i18n("Preview URL:"), topPage );
  81. topLayout->addWidget( previewLabel, 7, 0 );
  82. mPreviewUrl = new KURLRequester( topPage );
  83. topLayout->addWidget( mPreviewUrl, 7, 1 );
  84. TQLabel *summaryLabel = new TQLabel( i18n("Summary:"), topPage );
  85. topLayout->addMultiCellWidget( summaryLabel, 8, 8, 0, 1 );
  86. mSummaryEdit = new KTextEdit( topPage );
  87. topLayout->addMultiCellWidget( mSummaryEdit, 9, 9, 0, 1 );
  88. KUser user;
  89. mAuthorEdit->setText(user.fullName());
  90. }
  91. UploadDialog::~UploadDialog()
  92. {
  93. mEntryList.clear();
  94. }
  95. void UploadDialog::slotOk()
  96. {
  97. if ( mNameEdit->text().isEmpty() ) {
  98. KMessageBox::error( this, i18n("Please put in a name.") );
  99. return;
  100. }
  101. Entry *entry = new Entry;
  102. mEntryList.append( entry );
  103. entry->setName( mNameEdit->text() );
  104. entry->setAuthor( mAuthorEdit->text() );
  105. entry->setAuthorEmail( mEmailEdit->text() );
  106. entry->setVersion( mVersionEdit->text() );
  107. entry->setRelease( mReleaseSpin->value() );
  108. entry->setLicence( mLicenceCombo->currentText() );
  109. entry->setPreview( KURL( mPreviewUrl->url().section("/", -1) ), mLanguageCombo->currentText() );
  110. entry->setSummary( mSummaryEdit->text(), mLanguageCombo->currentText() );
  111. if ( mPayloadUrl.isValid() ) {
  112. TDEConfig *conf = kapp->config();
  113. conf->setGroup( TQString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()) );
  114. conf->writeEntry("name", mNameEdit->text());
  115. conf->writeEntry("author", mAuthorEdit->text());
  116. conf->writeEntry("email", mEmailEdit->text());
  117. conf->writeEntry("version", mVersionEdit->text());
  118. conf->writeEntry("release", mReleaseSpin->value());
  119. conf->writeEntry("licence", mLicenceCombo->currentText());
  120. conf->writeEntry("preview", mPreviewUrl->url());
  121. conf->writeEntry("summary", mSummaryEdit->text());
  122. conf->writeEntry("language", mLanguageCombo->currentText());
  123. conf->sync();
  124. }
  125. mEngine->upload( entry );
  126. accept();
  127. }
  128. void UploadDialog::setPreviewFile( const TQString &previewFile )
  129. {
  130. mPreviewUrl->setURL( previewFile );
  131. }
  132. void UploadDialog::setPayloadFile( const TQString &payloadFile )
  133. {
  134. mPayloadUrl = payloadFile;
  135. TDEConfig *conf = kapp->config();
  136. conf->setGroup( TQString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()) );
  137. TQString name = conf->readEntry("name");
  138. TQString author = conf->readEntry("author");
  139. TQString email = conf->readEntry("email");
  140. TQString version = conf->readEntry("version");
  141. TQString release = conf->readEntry("release");
  142. TQString preview = conf->readEntry("preview");
  143. TQString summary = conf->readEntry("summary");
  144. TQString lang = conf->readEntry("language");
  145. TQString licence = conf->readEntry("licence");
  146. mNameEdit->clear();
  147. mAuthorEdit->clear();
  148. mEmailEdit->clear();
  149. mVersionEdit->clear();
  150. mReleaseSpin->setValue(1);
  151. mPreviewUrl->clear();
  152. mSummaryEdit->clear();
  153. mLanguageCombo->setCurrentItem(0);
  154. mLicenceCombo->setCurrentItem(0);
  155. if(!name.isNull())
  156. {
  157. int prefill = KMessageBox::questionYesNo(this, i18n("Old upload information found, fill out fields?"),TQString::null,i18n("Fill Out"),i18n("Do Not Fill Out"));
  158. if(prefill == KMessageBox::Yes)
  159. {
  160. mNameEdit->setText(name);
  161. mAuthorEdit->setText(author);
  162. mEmailEdit->setText(email);
  163. mVersionEdit->setText(version);
  164. mReleaseSpin->setValue(release.toInt());
  165. mPreviewUrl->setURL(preview);
  166. mSummaryEdit->setText(summary);
  167. if(!lang.isEmpty()) mLanguageCombo->setCurrentText(lang);
  168. if(!licence.isEmpty()) mLicenceCombo->setCurrentText(licence);
  169. }
  170. }
  171. }