summaryrefslogtreecommitdiff
diff options
-rw-r--r--HACKING5
-rw-r--r--src/Makefile.am1
-rw-r--r--src/quicklauncher/chrome-handler.vala178
-rw-r--r--src/quicklauncher/prism-handler.vala17
-rw-r--r--src/quicklauncher/quicklauncher-manager.vala98
-rw-r--r--src/unity.vala2
-rw-r--r--vapi/clutk-0.3.vapi4
7 files changed, 294 insertions, 11 deletions
diff --git a/HACKING b/HACKING
index ac09e1863..0afe2e72e 100644
--- a/HACKING
+++ b/HACKING
@@ -36,3 +36,8 @@ Bootperformance Logging:
you can then produce a bootchart with this by running the tools/makebootchart.py
script:
./tools/makebootchart.py --input=/tmp/unity.log --output=/tmp/unity.svg
+
+
+Webapp switching:
+ Unity can use two webapp systems, prism and chromium, you can toggle between
+ the two by setting the gconf key "/apps/unity/webapp_use_chromium" on or off
diff --git a/src/Makefile.am b/src/Makefile.am
index 9051cc418..f38316a6e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -90,6 +90,7 @@ places_sources = \
quicklauncher_sources = \
quicklauncher/application-model.vala \
+ quicklauncher/chrome-handler.vala \
quicklauncher/launcher-model.vala \
quicklauncher/launcher-view.vala \
quicklauncher/prism-handler.vala \
diff --git a/src/quicklauncher/chrome-handler.vala b/src/quicklauncher/chrome-handler.vala
new file mode 100644
index 000000000..353f9ac83
--- /dev/null
+++ b/src/quicklauncher/chrome-handler.vala
@@ -0,0 +1,178 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/*
+ * Copyright (C) 2009 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by Gordon Allott <gord.allott@canonical.com>
+ *
+ */
+
+namespace Unity.Quicklauncher
+{
+
+ public class ChromiumWebApp : Object
+ {
+ static const string webapp_desktop_template = """[Desktop Entry]
+Version=1.0
+Name=%s
+GenericName=Web Browser
+Exec=chromium-browser -app=%s
+Terminal=false
+Type=Application
+Icon=chromium-browser
+Categories=Network;
+MimeType=text/html;
+StartupWMClass=Chromium
+StartupNotify=true
+""";
+
+ public string url {get; construct;}
+ public string name;
+ public string id;
+ string webapp_dir;
+
+ public ChromiumWebApp (string address)
+ {
+ Object (url:address);
+ }
+
+ construct
+ {
+ //FIXME - we need to get a "name" for webapps somehow, not sure how...
+ var split_url = url.split ("://", 2);
+ this.name = split_url[1];
+
+ try {
+ var regex = new Regex ("(/)");
+ name = regex.replace (name, -1, 0, "-");
+ } catch (RegexError e) {
+ warning ("%s", e.message);
+ }
+
+ this.id = name;
+ this.webapp_dir = Environment.get_home_dir () + "/.local/share/applications/";
+
+ bool exists = check_existance_of_app ();
+ if (!exists)
+ {
+ build_webapp ();
+ }
+ }
+
+ /* checks for the webapp given based on the url stored */
+ private bool check_existance_of_app ()
+ {
+ if (this.url == "")
+ {
+ return true;
+ }
+
+ var webapp_dir_file = File.new_for_path (webapp_dir + @"chromium-webapp-$name.desktop");
+ if (webapp_dir_file.query_exists (null))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ private void build_webapp ()
+ {
+ string webapp_desktop = webapp_desktop_template.printf (name, id);
+ debug ("building " + @"chromium-webapp-$name.desktop");
+
+ var webapp_directory = File.new_for_path (webapp_dir);
+ try
+ {
+ debug ("attempting to build parent directorys for %s", webapp_dir);
+ if (!webapp_directory.query_exists (null))
+ {
+ webapp_directory.make_directory_with_parents (null);
+ }
+ } catch (Error e)
+ {
+ warning ("%s", e.message);
+ return;
+ }
+
+ var desktop_file = File.new_for_path (webapp_dir + @"chromium-webapp-$name.desktop");
+ try
+ {
+ var file_stream = desktop_file.create (FileCreateFlags.NONE, null);
+ var data_stream = new DataOutputStream (file_stream);
+ data_stream.put_string (webapp_desktop, null);
+ data_stream.close (null);
+ debug ("wrote to %s", webapp_dir + @"chromium-webapp-$name.desktop");
+ } catch (Error e)
+ {
+ warning ("could not write to %s/%s.desktop", webapp_dir, name);
+ return;
+ }
+ }
+
+ public void add_to_favorites ()
+ {
+ var favorites = Launcher.Favorites.get_default ();
+ string uid = get_fav_uid ();
+ if (uid != "")
+ {
+ // we are a favorite already
+ warning ("%s is already a favorite", name);
+ return;
+ }
+
+ string desktop_path = webapp_dir + @"chromium-webapp-$name.desktop";
+ uid = "webapp-" + Path.get_basename (desktop_path);
+ try {
+ var regex = new Regex ("""\+""");
+ uid = regex.replace (uid, -1, 0, "");
+ } catch (Error e)
+ {
+ warning ("regular expression error: %s", e.message);
+ }
+
+
+ // we are not a favorite and we need to be favorited!
+ favorites.set_string (uid, "type", "application");
+ favorites.set_string (uid, "desktop_file", desktop_path);
+ favorites.add_favorite (uid);
+ }
+
+
+ /**
+ * gets the favorite uid for this desktop file
+ */
+ private string get_fav_uid ()
+ {
+ string myuid = "";
+ string my_desktop_path = webapp_dir + @"chromium-webapp-$name.desktop";
+ var favorites = Launcher.Favorites.get_default ();
+ unowned SList<string> favorite_list = favorites.get_favorites();
+ foreach (weak string uid in favorite_list)
+ {
+ // we only want favorite *applications* for the moment
+ var type = favorites.get_string(uid, "type");
+ if (type != "application")
+ continue;
+
+ string desktop_file = favorites.get_string(uid, "desktop_file");
+ if (desktop_file == my_desktop_path)
+ {
+ myuid = uid;
+ }
+ }
+ return myuid;
+ }
+ }
+
+}
diff --git a/src/quicklauncher/prism-handler.vala b/src/quicklauncher/prism-handler.vala
index 3714cdc4a..8c5591d71 100644
--- a/src/quicklauncher/prism-handler.vala
+++ b/src/quicklauncher/prism-handler.vala
@@ -20,7 +20,10 @@
namespace Unity.Quicklauncher
{
- const string webapp_ini_template = """[Parameters]
+
+ public class Prism : Object
+ {
+ static const string webapp_ini_template = """[Parameters]
id=%s@unity.app
name=%s
uri=%s
@@ -29,7 +32,7 @@ location=no
sidebar=no
navigation=no""";
- const string webapp_desktop_template = """[Desktop Entry]
+ static const string webapp_desktop_template = """[Desktop Entry]
Name=%s
Type=Application
Comment=Web Application
@@ -40,8 +43,6 @@ StartupNotify=true
Icon=/usr/share/pixmaps/prism.png
""";
- public class Prism : Object
- {
public string url {get; construct;}
public string name;
public string id;
@@ -148,6 +149,14 @@ Icon=/usr/share/pixmaps/prism.png
string desktop_path = webapp_dir + "/%s.desktop".printf (name);
uid = "webapp-" + Path.get_basename (desktop_path);
+ try {
+ var regex = new Regex ("""\+""");
+ uid = regex.replace (uid, -1, 0, "");
+ } catch (Error e)
+ {
+ warning ("regular expression error: %s", e.message);
+ }
+
// we are not a favorite and we need to be favorited!
favorites.set_string (uid, "type", "application");
favorites.set_string (uid, "desktop_file", desktop_path);
diff --git a/src/quicklauncher/quicklauncher-manager.vala b/src/quicklauncher/quicklauncher-manager.vala
index 132d79146..e3349ca5e 100644
--- a/src/quicklauncher/quicklauncher-manager.vala
+++ b/src/quicklauncher/quicklauncher-manager.vala
@@ -30,6 +30,21 @@ namespace Unity.Quicklauncher
private Launcher.Appman appman;
private Launcher.Session session;
+ // lazy init of gconf here :-) wait's until we need it
+ private GConf.Client? gconf_client_;
+ private GConf.Client? gconf_client {
+ get {
+ if (this.gconf_client_ is GConf.Client)
+ {
+ return this.gconf_client_;
+ }
+ else
+ {
+ return this.gconf_client_ = GConf.Client.get_default ();
+ }
+ }
+ }
+
construct
{
START_FUNCTION ();
@@ -54,6 +69,36 @@ namespace Unity.Quicklauncher
END_FUNCTION ();
}
+ // returns which string is the currently set webapp device
+ private string get_webapp_device ()
+ {
+ //check to see the unity dir exists
+ try {
+ bool dir_exists = this.gconf_client.dir_exists (UNITY_CONF_PATH);
+ if (!dir_exists)
+ {
+ // make the directory
+ this.gconf_client.add_dir (UNITY_CONF_PATH,
+ GConf.ClientPreloadType.NONE);
+ }
+ }
+ catch (Error e) {
+ warning ("%s", e.message);
+ }
+
+ try {
+ bool value = this.gconf_client.get_bool (UNITY_CONF_PATH + "/webapp_use_chromium");
+ if (value)
+ {
+ return "chromium";
+ }
+ }
+ catch (Error e) {
+ return "prism";
+ }
+ return "prism";
+ }
+
private bool on_drag_motion (Ctk.Actor actor, Gdk.DragContext context,
int x, int y, uint time_)
{
@@ -66,7 +111,16 @@ namespace Unity.Quicklauncher
debug ("on_drag_drop called");
if (context.targets != null)
{
- Gdk.Atom target_type = (Gdk.Atom) context.targets.nth_data (Unity.dnd_targets.TARGET_URL);
+ Gtk.TargetList tl;
+ Gdk.Atom target_type;
+ // silly tricking vala into passing an array with no elements.
+ // if anyone knows a way of doing this properly, please replace!
+ Gtk.TargetEntry[]? targets = null;
+ tl = new Gtk.TargetList (targets);
+ tl.add_uri_targets (0);
+
+ target_type = Ctk.drag_dest_find_target (context, tl);
+
if (target_type.name () == "")
{
warning ("bad DND type");
@@ -121,6 +175,25 @@ namespace Unity.Quicklauncher
Gtk.drag_finish (context, dnd_success, delete_selection_data, time_);
}
+ private bool test_url (string url)
+ {
+ // just returns if the given string is really a url
+ try {
+ Regex match_url = new Regex (
+ """((https?|s?ftp):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"""
+ );
+ if (match_url.match (url))
+ {
+ return true;
+ }
+
+ } catch (RegexError e) {
+ warning ("%s", e.message);
+ return false;
+ }
+ return false;
+ }
+
private bool handle_uri (string uri)
{
debug ("handling uri: " + uri);
@@ -137,11 +210,26 @@ namespace Unity.Quicklauncher
debug ("clean uri: " + clean_uri);
var split_uri = clean_uri.split ("://", 2);
- if ("http" in split_uri[0])
+
+ if (test_url (clean_uri))
{
- //we have a http url, prism it
- var webapp = new Prism (clean_uri);
- webapp.add_to_favorites ();
+ //we have a http url, webapp it
+ string webapp_device = this.get_webapp_device ();
+ switch (webapp_device) {
+ case "prism":
+ var webapp = new Prism (clean_uri);
+ webapp.add_to_favorites ();
+ break;
+
+ case "chromium":
+ var webapp = new ChromiumWebApp (clean_uri);
+ webapp.add_to_favorites ();
+ break;
+
+ default:
+ warning ("unknown webapp device %s", webapp_device);
+ break;
+ }
}
else if (".desktop" in Path.get_basename (clean_uri))
diff --git a/src/unity.vala b/src/unity.vala
index abb130421..596304fab 100644
--- a/src/unity.vala
+++ b/src/unity.vala
@@ -19,5 +19,5 @@
namespace Unity
{
-
+ public static const string UNITY_CONF_PATH = "/apps/unity";
}
diff --git a/vapi/clutk-0.3.vapi b/vapi/clutk-0.3.vapi
index 7c392533f..24119187c 100644
--- a/vapi/clutk-0.3.vapi
+++ b/vapi/clutk-0.3.vapi
@@ -13,7 +13,7 @@ namespace Ctk {
public bool get_effects_painting ();
public void get_padding (Ctk.Padding padding);
public Ctk.ActorState get_state ();
- public void get_stored_allocation (out Clutter.ActorBox box);
+ public void get_stored_allocation (Clutter.ActorBox box);
public unowned string get_tooltip_text ();
public void recurse_get_stored_allocation_box (Clutter.ActorBox box);
public void remove_all_effects ();
@@ -408,6 +408,8 @@ namespace Ctk {
[CCode (cheader_filename = "clutk/clutk.h")]
public static void dnd_init (Gtk.Widget widget, Gtk.TargetEntry[] targets);
[CCode (cheader_filename = "clutk/clutk.h")]
+ public static Gdk.Atom drag_dest_find_target (Gdk.DragContext context, Gtk.TargetList target_list);
+ [CCode (cheader_filename = "clutk/clutk.h")]
public static bool drag_dest_is_dest (Ctk.Actor widget);
[CCode (cheader_filename = "clutk/clutk.h")]
public static void drag_dest_start (Ctk.Actor widget);