]> cloud.milkyroute.net Git - dolphin.git/blob - src/protocolcombo.cpp
don't invoke a non existent slot
[dolphin.git] / src / protocolcombo.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Aaron J. Seigo (<aseigo@kde.org>) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include <q3popupmenu.h>
21
22 #include <kdebug.h>
23 #include <kprotocolinfo.h>
24 #include <kprotocolmanager.h>
25
26 #include "protocolcombo.h"
27
28 const static int customProtocolIndex = 0;
29
30 ProtocolCombo::ProtocolCombo(const QString& protocol, UrlNavigator* parent)
31 : UrlNavigatorButton(-1, parent),
32 m_protocols(KProtocolInfo::protocols())
33 {
34 qSort(m_protocols);
35 QStringList::iterator it = m_protocols.begin();
36 QStringList::iterator itEnd = m_protocols.end();
37 Q3PopupMenu* menu = new Q3PopupMenu(this);
38 while (it != itEnd)
39 {
40 //kDebug() << "info for " << *it << " "
41 // << KProtocolInfo::protocolClass(*it) << endl;
42 //TODO: wow this is ugly. or .. is it? ;) we need a way to determine
43 // if a protocol is appropriate for use in a file manager. hum!
44 //if (KProtocolInfo::capabilities(*it).findIndex("filemanager") == -1)
45 if (KProtocolInfo::protocolClass(*it) == ":" ||
46 !KProtocolManager::supportsWriting(*it))
47 {
48 //kDebug() << "!!! removing " << *it << endl;
49 QStringList::iterator tempIt = it;
50 ++tempIt;
51 m_protocols.erase(it);
52 it = tempIt;
53 }
54 else
55 {
56 ++it;
57 }
58 }
59
60 // setEditable(true);
61 // menu->insertItem("", customProtocolIndex);
62 // menu->insertStringList(m_protocols);
63 int i = 0;
64 for (QStringList::const_iterator it = m_protocols.constBegin();
65 it != m_protocols.constEnd();
66 ++it, ++i)
67 {
68 menu->insertItem(*it, i);
69 }
70 //menu->insertItems(m_protocols);
71 connect(menu, SIGNAL(activated(int)), this, SLOT(setProtocol(int)));
72 setText(protocol);
73 setMenu(menu);
74 setFlat(true);
75 }
76
77
78 // #include <kurl.h>
79 // #include "urlnavigator.h"
80 void ProtocolCombo::setProtocol(const QString& protocol)
81 {
82 setText(protocol);
83 // if (KProtocolInfo::isKnownProtocol(protocol))
84 // int index = m_protocols.findIndex(protocol);
85 // if (index == -1)
86 // {
87 // changeItem(protocol, customProtocolIndex);
88 // setCurrentItem(customProtocolIndex);
89 // }
90 // else
91 // {
92 // setCurrentItem(index + 1);
93 // }
94 }
95
96 void ProtocolCombo::setProtocol(int index)
97 {
98 if (index < 0 || index > m_protocols.count())
99 {
100 return;
101 }
102
103 QString protocol = m_protocols[index];
104 kDebug() << "setProtocol " << index << " " << protocol << endl;
105 setText(protocol);
106 emit activated(protocol);
107 /* */
108 }
109
110 QString ProtocolCombo::currentProtocol() const
111 {
112 return text(); //currentText();
113 }
114
115 #include "protocolcombo.moc"