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.

providerdialog.cpp 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <tqlayout.h>
  18. #include <tqstring.h>
  19. #include <tqlabel.h>
  20. #include <tdelistview.h>
  21. #include <tdelocale.h>
  22. #include <tdemessagebox.h>
  23. #include "engine.h"
  24. #include "provider.h"
  25. #include "providerdialog.h"
  26. #include "providerdialog.moc"
  27. using namespace KNS;
  28. class ProviderItem : public TDEListViewItem
  29. {
  30. public:
  31. ProviderItem( TDEListView *parent, Provider *provider ) :
  32. TDEListViewItem( parent ), mProvider( provider )
  33. {
  34. setText( 0, provider->name() );
  35. }
  36. Provider *provider() { return mProvider; }
  37. private:
  38. Provider *mProvider;
  39. };
  40. ProviderDialog::ProviderDialog( Engine *engine, TQWidget *parent ) :
  41. KDialogBase( Plain, i18n("Hot New Stuff Providers"), Ok | Cancel, Cancel,
  42. parent, 0, false, true ),
  43. mEngine( engine )
  44. {
  45. TQFrame *topPage = plainPage();
  46. TQBoxLayout *topLayout = new TQVBoxLayout( topPage );
  47. TQLabel *description = new TQLabel( i18n("Please select one of the providers listed below:"), topPage );
  48. topLayout->addWidget( description );
  49. mListView = new TDEListView( topPage );
  50. mListView->addColumn( i18n("Name") );
  51. topLayout->addWidget( mListView );
  52. }
  53. void ProviderDialog::clear()
  54. {
  55. mListView->clear();
  56. }
  57. void ProviderDialog::addProvider( Provider *provider )
  58. {
  59. new ProviderItem( mListView, provider );
  60. if ( mListView->childCount() == 1 ) {
  61. mListView->setSelected(mListView->firstChild(), true);
  62. } else if (mListView->childCount() > 1) {
  63. mListView->setSelected(mListView->firstChild(), false);
  64. }
  65. }
  66. void ProviderDialog::slotOk()
  67. {
  68. ProviderItem *item = static_cast<ProviderItem *>( mListView->selectedItem() );
  69. if ( !item ) {
  70. KMessageBox::error( this, i18n("No provider selected.") );
  71. return;
  72. }
  73. mEngine->requestMetaInformation( item->provider() );
  74. accept();
  75. }