[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: [PATCH] auto-completing URLs on Ctrl-Enter
From:       Tony <tonys111 () comcast ! net>
Date:       2006-02-03 4:10:39
Message-ID: 43E2D7BF.7050206 () comcast ! net
[Download RAW message or body]

Carsten Pfeiffer wrote:
> On Wednesday 01 February 2006 23:45, Jonas Bähr wrote:
>
>   
>> What do you think about Ctrl+Space? It's used for autocompletion in almost
>> every IDE (including KDevelop)...
>>     
>
> Actually I've wanted to use Ctrl-Space for "substring" completion (Ctrl-T for 
> ages, but usually overloaded by other actions and therefore non-functional).
>
> For those who don't know it, substring completion for "foo" would return all 
> entries that contain "foo" anywhere.
>
> Because Ctrl-Space can be considered a "general completion shortcut", as 
> you've mentioned yourself, I would prefer it to be useful in all applications 
> instead of only in a very specific konqueror completion mode.
>
> Cheers,
> Carsten
>   

Attached is a update containing most of the latest suggestions, as well 
as a patch for Makefile.am... I'm currently not familiar with the 
entry.desktop files in i18n and didn't have time to look into it 
tonight, but if that is the correct route to take let me know and I'll 
figure it out.

Thanks,
-Tony


["konq_combo-autowrap.3.diff" (text/x-patch)]

--- /home/tonys111/rpm/BUILD/kdebase-3.5.0.original/konqueror/konq_combo.cc	2005-11-19 \
                06:04:00.000000000 -0500
+++ konq_combo.cc	2006-02-02 23:08:14.000000000 -0500
@@ -31,6 +31,7 @@
 #include <kurldrag.h>
 #include <konq_mainwindow.h>
 #include <kstringhandler.h>
+#include <kstandarddirs.h>
 
 #include <dcopclient.h>
 
@@ -383,6 +384,77 @@
       setCurrentItem( temporary );
 }
 
+/* read in extra URL suffixes from "data" dir, konqueror/url_suffixes.desktop,
+ * suffixes are seperated by a comma(,), and optional space(s) and they should
+ * include the leading dot(.).
+ * example:
+ * [Suffixes]
+ * Name=.edu, .gov
+ * Name[de]=.de
+ */
+static QStringList getExtraURLSuffixes()
+{
+    const QString filename = KGlobal::dirs()->findResource("data", \
"konqueror/url_suffixes.desktop"); +
+	if (!filename.isEmpty())
+    {
+        KSimpleConfig config (filename, true);
+        config.setGroup("Suffixes");
+
+        const QString entry = config.readEntry("Name");
+
+		if (!entry.isEmpty())
+            return QStringList::split(QRegExp(", *"), entry);
+    }
+
+    return QStringList();
+}
+
+static bool autoWrapURL(QLineEdit *edit)
+{
+    const QString txt (edit->text());
+    const int lastSlash = txt.findRev('/');
+
+    // prevent already-complete URLs from being auto-wrapped
+    if (lastSlash == -1 || lastSlash == (txt.find("://") + 2))
+    {
+        int oldlen = 0;
+        static QStringList suffixes;
+        QStringList::const_iterator it;
+
+        if (!suffixes.count())
+        {
+            suffixes << ".com" << ".org" << ".net";
+            suffixes += getExtraURLSuffixes();
+        }
+
+        it = suffixes.begin();
+
+        if (txt.findRev('.') != -1)
+        {
+            for (QStringList::const_iterator end = suffixes.end(); it != end; ++it)
+            {
+                if (txt.endsWith(*it))
+                {
+                    oldlen = (*it).length();
+
+                    if (++it == end)
+                        it = suffixes.begin();
+
+                    break;
+                }
+            }
+        }
+
+        // it == end() should be impossible, but im being paranoid
+        if (it != suffixes.end())
+            edit->setText(txt.left(txt.length() - oldlen) + (*it));
+        return true;
+    }
+
+    return false;
+}
+
 bool KonqCombo::eventFilter( QObject *o, QEvent *ev )
 {
     // Handle Ctrl+Del/Backspace etc better than the Qt widget, which always
@@ -395,6 +467,7 @@
 
             if ( e->key() == Key_Return || e->key() == Key_Enter ) {
                 m_modifier = e->state();
+
                 return false;
             }
 
@@ -406,6 +479,9 @@
                 e->accept();
                 return true;
             }
+
+            if (e->key() == Key_Space && e->state() & ControlButton)
+                return autoWrapURL(edit);
         }
 
         else if ( type == QEvent::MouseButtonDblClick ) {


["Makefile.am.diff" (text/x-patch)]

--- /home/tonys111/rpm/BUILD/kdebase-3.5.0.original/konqueror/Makefile.am	2005-10-10 \
                11:04:20.000000000 -0400
+++ Makefile.am	2006-02-02 22:56:58.000000000 -0500
@@ -10,7 +10,7 @@
 
 noinst_LTLIBRARIES = libkonqueror_intern.la
 konqdatadir = $(kde_datadir)/konqueror
-konqdata_DATA = konqueror.rc konq-simplebrowser.rc
+konqdata_DATA = konqueror.rc konq-simplebrowser.rc url_suffixes.desktop
 
 kde_apps_DATA = konqueror.desktop
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic