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
|
/***************************************************************************
* Copyright (C) 2006 by Aaron J. Seigo (<[email protected]>) *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <q3popupmenu.h>
#include <kdebug.h>
#include <kprotocolinfo.h>
#include <kprotocolmanager.h>
#include "protocolcombo.h"
const static int customProtocolIndex = 0;
ProtocolCombo::ProtocolCombo(const QString& protocol, UrlNavigator* parent)
: UrlNavigatorButton(-1, parent),
m_protocols(KProtocolInfo::protocols())
{
qSort(m_protocols);
QStringList::iterator it = m_protocols.begin();
QStringList::iterator itEnd = m_protocols.end();
Q3PopupMenu* menu = new Q3PopupMenu(this);
while (it != itEnd)
{
//kDebug() << "info for " << *it << " "
// << KProtocolInfo::protocolClass(*it) << endl;
//TODO: wow this is ugly. or .. is it? ;) we need a way to determine
// if a protocol is appropriate for use in a file manager. hum!
//if (KProtocolInfo::capabilities(*it).findIndex("filemanager") == -1)
if (KProtocolInfo::protocolClass(*it) == ":" ||
!KProtocolManager::supportsWriting(*it))
{
//kDebug() << "!!! removing " << *it << endl;
QStringList::iterator tempIt = it;
++tempIt;
m_protocols.erase(it);
it = tempIt;
}
else
{
++it;
}
}
// setEditable(true);
// menu->insertItem("", customProtocolIndex);
// menu->insertStringList(m_protocols);
int i = 0;
for (QStringList::const_iterator it = m_protocols.constBegin();
it != m_protocols.constEnd();
++it, ++i)
{
menu->insertItem(*it, i);
}
//menu->insertItems(m_protocols);
connect(menu, SIGNAL(activated(int)), this, SLOT(setProtocol(int)));
setText(protocol);
setPopup(menu);
setFlat(true);
}
// #include <kurl.h>
// #include "urlnavigator.h"
void ProtocolCombo::setProtocol(const QString& protocol)
{
setText(protocol);
// if (KProtocolInfo::isKnownProtocol(protocol))
// int index = m_protocols.findIndex(protocol);
// if (index == -1)
// {
// changeItem(protocol, customProtocolIndex);
// setCurrentItem(customProtocolIndex);
// }
// else
// {
// setCurrentItem(index + 1);
// }
}
void ProtocolCombo::setProtocol(int index)
{
if (index < 0 || index > m_protocols.count())
{
return;
}
QString protocol = m_protocols[index];
kDebug() << "setProtocol " << index << " " << protocol << endl;
setText(protocol);
emit activated(protocol);
/* */
}
QString ProtocolCombo::currentProtocol() const
{
return text(); //currentText();
}
#include "protocolcombo.moc"
|