summaryrefslogtreecommitdiffstats
path: root/src/urldlg.cpp
blob: 3507983a674aa73480e559f12cbda094886462a1 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/***************************************************************************
 *   Copyright (C) 2005-2007 by Rajko Albrecht                             *
 *   ral@alwins-world.de                                                   *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/
#include "urldlg.h"
#include <kcombobox.h>
#include <kurlrequester.h>
#include <tqlayout.h>
#include <kconfig.h>
#include <klocale.h>
#include <kglobal.h>
#include <klineedit.h>
#include <kurl.h>
#include <kdebug.h>

#include <tqlabel.h>

UrlDlg::UrlDlg(TQWidget *tqparent, const char *name)
 : KDialogBase(Plain, TQString(), Ok|Cancel|User1, Ok, tqparent, name,
                true,true, KStdGuiItem::clear())
{
    init_dlg();
}


UrlDlg::~UrlDlg()
{
}


/*!
    \fn UrlDlg::init_dlg
 */
void UrlDlg::init_dlg()
{
    TQVBoxLayout * topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint());
    TQLabel * label = new TQLabel(i18n("Open repository or working copy") , plainPage());
    topLayout->addWidget(label);

    KHistoryCombo * combo = new KHistoryCombo(0,"history_combo");
    combo->setDuplicatesEnabled(false);
    KConfig *kc = KGlobal::config();
    KConfigGroupSaver ks( kc, TQString::tqfromLatin1("Open-repository settings") );
    int max = kc->readNumEntry( TQString::tqfromLatin1("Maximum history"), 15 );
    combo->setMaxCount( max );
    TQStringList list = kc->readListEntry( TQString::tqfromLatin1("History") );
    combo->setHistoryItems(list);
    combo->setMinimumWidth(100);
    combo->adjustSize();
    if (combo->width()>300) {
        combo->resize(300,combo->height());
    }

    urlRequester_ = new KURLRequester(combo, plainPage(), "urlRequester");
    topLayout->addWidget( urlRequester_ );
    urlRequester_->setFocus();
    KFile::Mode mode = static_cast<KFile::Mode>(KFile::ExistingOnly|KFile::Directory);
    urlRequester_->setMode(mode);
    connect(urlRequester_->comboBox(),TQT_SIGNAL(textChanged(const TQString&)),TQT_SLOT(slotTextChanged(const TQString&)));
    enableButtonOK( false );
    enableButton( KDialogBase::User1, false );
    connect( this, TQT_SIGNAL(user1Clicked()), TQT_SLOT(slotClear()));
    urlRequester_->adjustSize();
    resize(TQSize(400,tqsizeHint().height()));
}

/*!
    \fn UrlDlg::accept()
 */
void UrlDlg::accept()
{
    KHistoryCombo *combo = static_cast<KHistoryCombo*>(urlRequester_->comboBox());
    if (combo) {
        combo->addToHistory(urlRequester_->url());
        KConfig *kc = KGlobal::config();
        KConfigGroupSaver ks(kc, TQString::tqfromLatin1("Open-repository settings"));
        kc->writeEntry(TQString::tqfromLatin1("History"), combo->historyItems());
        kc->sync();
    }
    KDialogBase::accept();
}


/*!
    \fn UrlDlg::slotTextChanged(const TQString&)
 */
void UrlDlg::slotTextChanged(const TQString&text)
{
    bool state = !text.stripWhiteSpace().isEmpty();
    enableButtonOK( state );
    enableButton( KDialogBase::User1, state );
}


/*!
    \fn UrlDlg::slotClear()
 */
void UrlDlg::slotClear()
{
    urlRequester_->clear();
}


/*!
    \fn UrlDlg::selectedURL()
 */
KURL UrlDlg::selectedURL()
{
    if ( result() == TQDialog::Accepted ) {
        KURL uri = urlRequester_->url();
        return uri;
        //return KURL::fromPathOrURL( urlRequester_->url() );
    } else {
        return KURL();
    }
}


/*!
    \fn UrlDlg::getURL(TQWidget*tqparent)
 */
KURL UrlDlg::getURL(TQWidget*tqparent)
{
    UrlDlg dlg(tqparent);
    dlg.setCaption(i18n("Open"));
    dlg.exec();
    const KURL& url = dlg.selectedURL();
    return url;
}

#include "urldlg.moc"