┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/protocolcombo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocolcombo.cpp')
-rw-r--r--src/protocolcombo.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/protocolcombo.cpp b/src/protocolcombo.cpp
new file mode 100644
index 000000000..b91b102cd
--- /dev/null
+++ b/src/protocolcombo.cpp
@@ -0,0 +1,114 @@
+/***************************************************************************
+ * 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 "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)
+ {
+ //kdDebug() << "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) == ":" ||
+ !KProtocolInfo::supportsWriting(*it))
+ {
+ //kdDebug() << "!!! removing " << *it << endl;
+ QStringList::iterator tempIt = it;
+ ++tempIt;
+ m_protocols.remove(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];
+kdDebug() << "setProtocol " << index << " " << protocol << endl;
+ setText(protocol);
+ emit activated(protocol);
+/* */
+}
+
+QString ProtocolCombo::currentProtocol() const
+{
+ return text(); //currentText();
+}
+
+#include "protocolcombo.moc"