moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / keduca / keducabuilder / keducaeditorstartdialog.cpp
blob88cf9305051187db1a5b8f145b6b532118bd724a
1 /***************************************************************************
2 keducaeditorstartdialog.cpp - description
3 -------------------
4 begin : Fri May 10 2002
5 copyright : (C) 2002 by Klas Kalass
6 email : klas@kde.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17 #include <qradiobutton.h>
18 #include <qbuttongroup.h>
20 #include <kdebug.h>
21 #include <kurlrequester.h>
22 #include <kmessagebox.h>
23 #include <klocale.h>
24 #include <kconfig.h>
25 #include <kcombobox.h>
27 #include "keducaeditorstartdialog.h"
28 #include "keducabuilder.h"
30 /**
32 KEducaEditorStartDialog::KEducaEditorStartDialog(KEducaBuilder * parent, const char* name, bool modal, WFlags fl)
33 :KEducaEditorStartDialogBase(parent, name, modal, fl),
34 _choice(NewDoc),
35 _maxRecentDocumentItems(20)
37 newDocumentRB->setFocus();
39 // read recent files
40 buildRecentFilesList();
42 // setup connections
43 urlRequester->setFilter( "application/x-edu");
45 connect( startChoiceBtnGrp, SIGNAL( clicked(int) ),
46 this, SLOT( slotChoiceChanged(int) ) );
49 /** based on code in kaction.cpp
51 void KEducaEditorStartDialog::buildRecentFilesList()
53 QString key;
54 QString value;
55 QString oldGroup;
56 KConfig *config = KGlobal::config();
58 oldGroup = config->group();
60 config->setGroup( "RecentFiles" );
62 // read file list
63 for( unsigned int i = 1 ; i <= _maxRecentDocumentItems ; i++ )
65 key = QString( "File%1" ).arg( i );
66 value = config->readEntry( key, QString::null );
68 if (!value.isNull())
69 recentDocumentCB->insertURL( KURL(value) );
72 config->setGroup( oldGroup );
75 KEducaEditorStartDialog::~KEducaEditorStartDialog() {
79 void KEducaEditorStartDialog::slotChoiceChanged(int id) {
80 _choice = id+1;
83 KURL KEducaEditorStartDialog::getURL()const{
84 switch(_choice) {
85 case OpenDoc:
86 return KURL(urlRequester->url());
87 break;
88 case OpenRecentDoc:
89 return KURL(recentDocumentCB->currentText());
90 break;
91 default:
92 break;
95 return KURL();
98 int KEducaEditorStartDialog::exec() {
99 int ret = KEducaEditorStartDialogBase::exec();
100 if ( ret == KEducaEditorStartDialogBase::Rejected )
101 _choice = KEducaEditorStartDialog::Rejected;
103 return _choice;
106 void KEducaEditorStartDialog::accept() {
107 if (((_choice == OpenDoc || _choice == OpenRecentDoc)
108 && getURL().isEmpty())) {
109 KMessageBox::sorry(this, i18n("You need to specify the file to open!"));
110 }else
111 KEducaEditorStartDialogBase::accept();
114 #include "keducaeditorstartdialog.moc"