summaryrefslogtreecommitdiffstats
path: root/keduca/keducabuilder/keducaeditorstartdialog.cpp
blob: 01bbc260a2335aa68eba3ea8e9efccab2cdeb30e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***************************************************************************
                          keducaeditorstartdialog.cpp  -  description
                             -------------------
    begin                : Fri May 10 2002
    copyright            : (C) 2002 by Klas Kalass
    email                : klas@kde.org
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include <tqradiobutton.h>
#include <tqbuttongroup.h>

#include <kdebug.h>
#include <kurlrequester.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kconfig.h>
#include <kcombobox.h>

#include "keducaeditorstartdialog.h"
#include "keducabuilder.h"

/**
 */
KEducaEditorStartDialog::KEducaEditorStartDialog(KEducaBuilder * parent, const char* name, bool modal, WFlags fl)
    :KEducaEditorStartDialogBase(parent,  name,  modal, fl),
     _choice(NewDoc),
     _maxRecentDocumentItems(20)
{
    newDocumentRB->setFocus();

    // read recent files
    buildRecentFilesList();

// setup connections
    urlRequester->setFilter( "application/x-edu");

    connect( startChoiceBtnGrp,  TQT_SIGNAL( clicked(int) ),
             this, TQT_SLOT( slotChoiceChanged(int) ) );
}

/** based on code in kaction.cpp
 */
void KEducaEditorStartDialog::buildRecentFilesList()
{
    TQString     key;
    TQString     value;
    TQString     oldGroup;
    KConfig *config = KGlobal::config();

    oldGroup = config->group();

    config->setGroup( "RecentFiles" );

    // read file list
    for( unsigned int i = 1 ; i <= _maxRecentDocumentItems ; i++ )
    {
        key = TQString( "File%1" ).tqarg( i );
        value = config->readEntry( key, TQString() );

        if (!value.isNull())
            recentDocumentCB->insertURL( KURL(value) );
    }

    config->setGroup( oldGroup );
}

KEducaEditorStartDialog::~KEducaEditorStartDialog() {

}

void KEducaEditorStartDialog::slotChoiceChanged(int id) {
    _choice = id+1;
}

KURL KEducaEditorStartDialog::getURL()const{
    switch(_choice) {
    case OpenDoc:
        return KURL(urlRequester->url());
        break;
    case OpenRecentDoc:
        return KURL(recentDocumentCB->currentText());
        break;
    default:
        break;
    }

    return KURL();
}

int KEducaEditorStartDialog::exec() {
    int ret = KEducaEditorStartDialogBase::exec();
    if ( ret == KEducaEditorStartDialogBase::Rejected )
        _choice = KEducaEditorStartDialog::Rejected;

    return _choice;
}

void KEducaEditorStartDialog::accept() {
    if (((_choice == OpenDoc || _choice == OpenRecentDoc)
          && getURL().isEmpty())) {
        KMessageBox::sorry(this, i18n("You need to specify the file to open!"));
    }else
        KEducaEditorStartDialogBase::accept();
}

#include "keducaeditorstartdialog.moc"