]> cloud.milkyroute.net Git - dolphin.git/blob - src/protocolcombo.cpp
commited initial version of Dolphin
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
19
20 #include <q3popupmenu.h>
21
22 #include <kdebug.h>
23 #include <kprotocolinfo.h>
24
25 #include "protocolcombo.h"
26
27 const static int customProtocolIndex = 0;
28
29 ProtocolCombo::ProtocolCombo(const QString& protocol, URLNavigator* parent)
30 : URLNavigatorButton(-1, parent),
31 m_protocols(KProtocolInfo::protocols())
32 {
33 qSort(m_protocols);
34 QStringList::iterator it = m_protocols.begin();
35 QStringList::iterator itEnd = m_protocols.end();
36 Q3PopupMenu* menu = new Q3PopupMenu(this);
37 while (it != itEnd)
38 {
39 //kdDebug() << "info for " << *it << " "
40 // << KProtocolInfo::protocolClass(*it) << endl;
41 //TODO: wow this is ugly. or .. is it? ;) we need a way to determine
42 // if a protocol is appropriate for use in a file manager. hum!
43 //if (KProtocolInfo::capabilities(*it).findIndex("filemanager") == -1)
44 if (KProtocolInfo::protocolClass(*it) == ":" ||
45 !KProtocolInfo::supportsWriting(*it))
46 {
47 //kdDebug() << "!!! removing " << *it << endl;
48 QStringList::iterator tempIt = it;
49 ++tempIt;
50 m_protocols.remove(it);
51 it = tempIt;
52 }
53 else
54 {
55 ++it;
56 }
57 }
58
59 // setEditable(true);
60 // menu->insertItem("", customProtocolIndex);
61 // menu->insertStringList(m_protocols);
62 int i = 0;
63 for (QStringList::const_iterator it = m_protocols.constBegin();
64 it != m_protocols.constEnd();
65 ++it, ++i)
66 {
67 menu->insertItem(*it, i);
68 }
69 //menu->insertItems(m_protocols);
70 connect(menu, SIGNAL(activated(int)), this, SLOT(setProtocol(int)));
71 setText(protocol);
72 setPopup(menu);
73 setFlat(true);
74 }
75
76
77 // #include <kurl.h>
78 // #include "urlnavigator.h"
79 void ProtocolCombo::setProtocol(const QString& protocol)
80 {
81 setText(protocol);
82 // if (KProtocolInfo::isKnownProtocol(protocol))
83 // int index = m_protocols.findIndex(protocol);
84 // if (index == -1)
85 // {
86 // changeItem(protocol, customProtocolIndex);
87 // setCurrentItem(customProtocolIndex);
88 // }
89 // else
90 // {
91 // setCurrentItem(index + 1);
92 // }
93 }
94
95 void ProtocolCombo::setProtocol(int index)
96 {
97 if (index < 0 || index > m_protocols.count())
98 {
99 return;
100 }
101
102 QString protocol = m_protocols[index];
103 kdDebug() << "setProtocol " << index << " " << protocol << endl;
104 setText(protocol);
105 emit activated(protocol);
106 /* */
107 }
108
109 QString ProtocolCombo::currentProtocol() const
110 {
111 return text(); //currentText();
112 }
113
114 #include "protocolcombo.moc"