KNewStuff
providerdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlayout.h>
00022 #include <qstring.h>
00023 #include <qlabel.h>
00024
00025 #include <klistview.h>
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028
00029 #include "engine.h"
00030 #include "provider.h"
00031
00032 #include "providerdialog.h"
00033 #include "providerdialog.moc"
00034
00035 using namespace KNS;
00036
00037 class ProviderItem : public KListViewItem
00038 {
00039 public:
00040 ProviderItem( KListView *parent, Provider *provider ) :
00041 KListViewItem( parent ), mProvider( provider )
00042 {
00043 setText( 0, provider->name() );
00044 }
00045
00046 Provider *provider() { return mProvider; }
00047
00048 private:
00049 Provider *mProvider;
00050 };
00051
00052 ProviderDialog::ProviderDialog( Engine *engine, QWidget *parent ) :
00053 KDialogBase( Plain, i18n("Hot New Stuff Providers"), Ok | Cancel, Cancel,
00054 parent, 0, false, true ),
00055 mEngine( engine )
00056 {
00057 QFrame *topPage = plainPage();
00058
00059 QBoxLayout *topLayout = new QVBoxLayout( topPage );
00060
00061 QLabel *description = new QLabel( i18n("Please select one of the providers listed below:"), topPage );
00062 topLayout->addWidget( description );
00063
00064 mListView = new KListView( topPage );
00065 mListView->addColumn( i18n("Name") );
00066 topLayout->addWidget( mListView );
00067 }
00068
00069 void ProviderDialog::clear()
00070 {
00071 mListView->clear();
00072 }
00073
00074 void ProviderDialog::addProvider( Provider *provider )
00075 {
00076 new ProviderItem( mListView, provider );
00077 if ( mListView->childCount() == 1 ) {
00078 mListView->setSelected(mListView->firstChild(), true);
00079 } else if (mListView->childCount() > 1) {
00080 mListView->setSelected(mListView->firstChild(), false);
00081 }
00082 }
00083
00084 void ProviderDialog::slotOk()
00085 {
00086 ProviderItem *item = static_cast<ProviderItem *>( mListView->selectedItem() );
00087 if ( !item ) {
00088 KMessageBox::error( this, i18n("No provider selected.") );
00089 return;
00090 }
00091
00092 mEngine->requestMetaInformation( item->provider() );
00093
00094 accept();
00095 }