korganizer Library API Documentation

downloaddialog.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 <qlayout.h>
00022 #include <qstring.h>
00023 
00024 #include <klistview.h>
00025 #include <klocale.h>
00026 
00027 #include "engine.h"
00028 #include "entry.h"
00029 
00030 #include "downloaddialog.h"
00031 #include "downloaddialog.moc"
00032 
00033 using namespace KNS;
00034 
00035 class KNewStuffItem : public KListViewItem
00036 {
00037   public:
00038     KNewStuffItem( KListView *parent, Entry *entry ) :
00039       KListViewItem( parent ), mEntry( entry )
00040     {
00041       setText( 0, entry->name() );
00042       setText( 1, entry->summary() );
00043       setText( 2, entry->version() );
00044       setText( 3, QString::number( entry->release() ) );
00045     }
00046       
00047     Entry *entry() { return mEntry; }
00048     
00049   private:
00050     Entry *mEntry;
00051 };
00052 
00053 DownloadDialog::DownloadDialog( Engine *newStuff, QWidget *parent ) :
00054   KDialogBase( Plain, i18n("Get Hot New Stuff"), Ok | Apply | Cancel, Cancel,
00055                parent, 0, false, true ),
00056   mNewStuff( newStuff )
00057 {
00058   QFrame *topPage = plainPage();
00059   
00060   QBoxLayout *topLayout = new QVBoxLayout( topPage );
00061   
00062   mListView = new KListView( topPage );
00063   mListView->addColumn( i18n("Name") );
00064   mListView->addColumn( i18n("Summary") );
00065   mListView->addColumn( i18n("Version") );
00066   mListView->addColumn( i18n("Release") );
00067   topLayout->addWidget( mListView );
00068 }
00069 
00070 void DownloadDialog::addEntry( Entry *entry )
00071 {
00072   new KNewStuffItem( mListView, entry );
00073 }
00074 
00075 void DownloadDialog::clear()
00076 {
00077   mListView->clear();
00078 }
00079 
00080 void DownloadDialog::slotApply()
00081 {
00082   KNewStuffItem *item =
00083     static_cast<KNewStuffItem *>( mListView->selectedItem() );
00084     
00085   if ( !item ) {
00086     return;
00087   }
00088 
00089   mNewStuff->download( item->entry() );
00090 }
00091 
00092 void DownloadDialog::slotOk()
00093 {
00094   slotApply();
00095   
00096   accept();
00097 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:08 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001