keduca
keducaeditorstartdialog.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 #include <qradiobutton.h>
00018 #include <qbuttongroup.h>
00019
00020 #include <kdebug.h>
00021 #include <kurlrequester.h>
00022 #include <kmessagebox.h>
00023 #include <klocale.h>
00024 #include <kconfig.h>
00025 #include <kcombobox.h>
00026
00027 #include "keducaeditorstartdialog.h"
00028 #include "keducabuilder.h"
00029
00032 KEducaEditorStartDialog::KEducaEditorStartDialog(KEducaBuilder * parent, const char* name, bool modal, WFlags fl)
00033 :KEducaEditorStartDialogBase(parent, name, modal, fl),
00034 _choice(NewDoc),
00035 _maxRecentDocumentItems(20)
00036 {
00037 newDocumentRB->setFocus();
00038
00039
00040 buildRecentFilesList();
00041
00042
00043 urlRequester->setFilter( "application/x-edu");
00044
00045 connect( startChoiceBtnGrp, SIGNAL( clicked(int) ),
00046 this, SLOT( slotChoiceChanged(int) ) );
00047 }
00048
00051 void KEducaEditorStartDialog::buildRecentFilesList()
00052 {
00053 QString key;
00054 QString value;
00055 QString oldGroup;
00056 KConfig *config = KGlobal::config();
00057
00058 oldGroup = config->group();
00059
00060 config->setGroup( "RecentFiles" );
00061
00062
00063 for( unsigned int i = 1 ; i <= _maxRecentDocumentItems ; i++ )
00064 {
00065 key = QString( "File%1" ).arg( i );
00066 value = config->readEntry( key, QString::null );
00067
00068 if (!value.isNull())
00069 recentDocumentCB->insertURL( KURL(value) );
00070 }
00071
00072 config->setGroup( oldGroup );
00073 }
00074
00075 KEducaEditorStartDialog::~KEducaEditorStartDialog() {
00076
00077 }
00078
00079 void KEducaEditorStartDialog::slotChoiceChanged(int id) {
00080 _choice = id+1;
00081 }
00082
00083 KURL KEducaEditorStartDialog::getURL()const{
00084 switch(_choice) {
00085 case OpenDoc:
00086 return KURL(urlRequester->url());
00087 break;
00088 case OpenRecentDoc:
00089 return KURL(recentDocumentCB->currentText());
00090 break;
00091 default:
00092 break;
00093 }
00094
00095 return KURL();
00096 }
00097
00098 int KEducaEditorStartDialog::exec() {
00099 int ret = KEducaEditorStartDialogBase::exec();
00100 if ( ret == KEducaEditorStartDialogBase::Rejected )
00101 _choice = KEducaEditorStartDialog::Rejected;
00102
00103 return _choice;
00104 }
00105
00106 void KEducaEditorStartDialog::accept() {
00107 if (((_choice == OpenDoc || _choice == OpenRecentDoc)
00108 && getURL().isEmpty())) {
00109 KMessageBox::sorry(this, i18n("You need to specify the file to open!"));
00110 }else
00111 KEducaEditorStartDialogBase::accept();
00112 }
00113
00114 #include "keducaeditorstartdialog.moc"