00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "recentprojectsdialogpage.h"
00022
00023 #include <QtGui/QWidget>
00024 #include <QtGui/QVBoxLayout>
00025 #include <QtGui/QListWidget>
00026
00027 #include <KDE/KLocalizedString>
00028 #include <KDE/KIcon>
00029 #include <KDE/KGlobal>
00030 #include <KDE/KConfig>
00031 #include <KDE/KConfigGroup>
00032
00033 #include <core/debughelper.h>
00034
00035 using namespace GluonCreator;
00036
00037 class RecentProjectsDialogPage::RecentProjectsDialogPagePrivate
00038 {
00039 public:
00040 RecentProjectsDialogPagePrivate( RecentProjectsDialogPage* qq )
00041 : widget( 0 ),
00042 q( qq )
00043 {
00044 }
00045
00046 void projectDoubleClicked( const QModelIndex& index )
00047 {
00048 QListWidgetItem* item = static_cast<QListWidgetItem*>( index.internalPointer() );
00049 if( item )
00050 emit q->projectRequested( item->data( Qt::UserRole ).toString() );
00051 }
00052 public:
00053 QListWidget* widget;
00054 private:
00055 RecentProjectsDialogPage* q;
00056 };
00057
00058 RecentProjectsDialogPage::RecentProjectsDialogPage()
00059 : KPageWidgetItem( new QWidget(), i18n( "Recent Projects" ) ),
00060 d( new RecentProjectsDialogPagePrivate( this ) )
00061 {
00062 setIcon( KIcon( "document-open-recent" ) );
00063
00064 d->widget = new QListWidget( widget() );
00065 connect( d->widget, SIGNAL( doubleClicked( QModelIndex ) ),
00066 SLOT( projectDoubleClicked( QModelIndex ) ) );
00067
00068 QVBoxLayout* layout = new QVBoxLayout( widget() );
00069 widget()->setLayout( layout );
00070 layout->addWidget( d->widget );
00071
00072 const KConfigGroup group = KGlobal::config()->group( "Recent Files" );
00073 const int entryCount = ( group.entryMap().count() / 2 );
00074
00075 for( int i = entryCount; i >= 1; --i )
00076 {
00077 const QString key = QString( "File%1" ).arg( i );
00078 const QString path = group.readPathEntry( key, QString() );
00079
00080 QListWidgetItem* item = new QListWidgetItem;
00081 item->setIcon( KIcon( "document-open-recent" ) );
00082 item->setText( QString( "%1\n%2" ).arg( KUrl( path ).fileName() ).arg( path ) );
00083 item->setData( Qt::UserRole, path );
00084 d->widget->addItem( item );
00085 }
00086 }
00087
00088 RecentProjectsDialogPage::~RecentProjectsDialogPage()
00089 {
00090 delete d;
00091 }
00092
00093 QString RecentProjectsDialogPage::selectedItem() const
00094 {
00095 QListWidgetItem* item = d->widget->currentItem();
00096 if( item )
00097 return item->data( Qt::UserRole ).toString();
00098 return QString();
00099 }
00100
00101 #include "creator/dialogs/recentprojectsdialogpage.moc"