summaryrefslogtreecommitdiffstats
path: root/ktouch/src/ktouchopenrequest.cpp
blob: a9100945d6086159b7af1b2582d203262e3e36b9 (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
115
116
117
118
119
120
121
/***************************************************************************
 *   ktouchopenrequest.cpp                                                 *
 *   ---------------------                                                 *
 *   Copyright (C) 2004 by Andreas Nicolai                                 *
 *   ghorwin@users.sourceforge.net                                         *
 *                                                                         *
 *   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 <tqlabel.h>
#include <tqbuttongroup.h>

#include <kpushbutton.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <tdefiledialog.h>
#include <tdelocale.h>
#include <ksqueezedtextlabel.h>
#include <tdemessagebox.h>
#include <tdelocale.h>

#include "ktouchopenrequest.h"
#include "ktouchopenrequest.moc"

KTouchOpenRequest::KTouchOpenRequest(TQWidget* parent, const char* name, bool modal, WFlags fl)
: KTouchOpenRequestDlg(parent,name, modal,fl)
{
}

int KTouchOpenRequest::requestFileToOpen(KURL& url, const TQString& caption, const TQString& title, 
      const TQString& currentText, const TQString& defaultText, const TQString& openText,
      const TQString& newText, KURL current_url, TQStringList defaultList, TQString emptyListText)
{
    setCaption(caption);
    openChoiceGroup->setTitle(title);
    currentRadioBtn->setText(currentText);
    presetRadioBtn->setText(defaultText);
    openFileRadioBtn->setText(openText);
    newRadioBtn->setText(newText);
    // Fill in current lecture URL or disable if not available
    if (current_url.isEmpty())  {
        currentLabel->setText("");
        currentRadioBtn->setEnabled(false);
        newRadioBtn->setChecked(true);
    }
    else {
        currentLabel->setText(current_url.url());
        currentRadioBtn->setEnabled(true);
        currentRadioBtn->setChecked(true);
    };
    // Fill preset combo with lecture files from the configuration object
    presetCombo->clear();
    if (defaultList.isEmpty()) {
        if (emptyListText.isEmpty())  presetCombo->insertItem(i18n("<no default files available>"));
        else                          presetCombo->insertItem(emptyListText);
        presetRadioBtn->setEnabled(false);
    }
    else {
        for (TQStringList::Iterator it = defaultList.begin(); it != defaultList.end(); ++it )
            presetCombo->insertItem(*it);
        presetRadioBtn->setEnabled(true);
    }
    presetCombo->setCurrentItem(0);
    radioBtnChanged();
    
    // Finally executre the dialog
    int result = exec();
    url = m_url;
    return result;
}

void KTouchOpenRequest::okBtnClicked() {
    if (currentRadioBtn->isChecked())
        m_url = currentLabel->text();
    if (presetRadioBtn->isChecked())
        m_url = presetCombo->currentText();
    if (newRadioBtn->isChecked())
        m_url = TQString();
    if (openFileRadioBtn->isChecked()) {
        if (openFileEdit->text().isEmpty()) {
            KMessageBox::error(this, i18n("Please select or enter a file name."));
            return;
        }
        KURL tmp = openFileEdit->text();
        if (!tmp.isValid()) {
            KMessageBox::error(this, i18n("The URL seems to be malformed; please correct it."));
            return;
        }
        m_url = tmp;
    };            
    TQDialog::accept();
}


void KTouchOpenRequest::radioBtnChanged() {
    if (currentRadioBtn->isChecked())   currentLabel->setEnabled(true);
    else                                currentLabel->setEnabled(false);
    if (presetRadioBtn->isChecked())    presetCombo->setEnabled(true);
    else                                presetCombo->setEnabled(false);
    if (openFileRadioBtn->isChecked()) {
        openFileEdit->setEnabled(true);
        browseBtn->setEnabled(true);
    }
    else {
        openFileEdit->setEnabled(false);
        browseBtn->setEnabled(false);
    }
}


void KTouchOpenRequest::browseBtnClicked() {
    KURL tmp = KFileDialog::getOpenURL(TQString(), TQString(), this, i18n("Select Training Lecture File") );
    if (!tmp.isEmpty())
        openFileEdit->setText(tmp.url());
}