summaryrefslogtreecommitdiff
path: root/src/themes
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2015-09-27 15:05:13 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2015-09-27 15:05:13 +0200
commit16fe2e5d0525422ba6ca5db9e92a93d17caae302 (patch)
treed6f1a9ed22335f6d0b457ccdd560b7525fb38d14 /src/themes
parent10af7615316fd91eef61cc66a8ede38a2bff3fdc (diff)
Imported Upstream version 0.6.6upstream/0.6.6
Diffstat (limited to 'src/themes')
-rw-r--r--src/themes/theme.vala36
-rw-r--r--src/themes/themeImporter.vala62
2 files changed, 98 insertions, 0 deletions
diff --git a/src/themes/theme.vala b/src/themes/theme.vala
index a7dd4f8..98e8994 100644
--- a/src/themes/theme.vala
+++ b/src/themes/theme.vala
@@ -115,6 +115,42 @@ public class Theme : GLib.Object {
return true;
}
+
+ /////////////////////////////////////////////////////////////////////
+ /// Exports the theme directory to an importable archive.
+ /////////////////////////////////////////////////////////////////////
+
+ public void export(string file) {
+
+ var archive = new ArchiveWriter();
+ bool success = true;
+
+ if (!archive.open(file)) {
+ warning("Cannot open file " + file + " for writing!");
+ success = false;
+ } else if (!archive.add(this.directory)) {
+ warning("Cannot append directory " + this.directory + " to archive!");
+ success = false;
+ }
+
+ archive.close();
+
+ if (success) {
+ var message = _("Successfully exported the theme \"%s\"!").printf(this.name);
+ var dialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, message);
+ dialog.run();
+ dialog.destroy();
+
+ } else {
+ var message = _("An error occured while exporting the theme \"%s\"! Please check the console output.").printf(this.name);
+ var dialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, message);
+ dialog.run();
+ dialog.destroy();
+ }
+ }
+
/////////////////////////////////////////////////////////////////////
/// Loads all images of the theme.
/////////////////////////////////////////////////////////////////////
diff --git a/src/themes/themeImporter.vala b/src/themes/themeImporter.vala
new file mode 100644
index 0000000..f110696
--- /dev/null
+++ b/src/themes/themeImporter.vala
@@ -0,0 +1,62 @@
+/////////////////////////////////////////////////////////////////////////
+// Copyright (c) 2011-2015 by Simon Schneegans
+//
+// 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 3 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, see <http://www.gnu.org/licenses/>.
+/////////////////////////////////////////////////////////////////////////
+
+namespace GnomePie {
+
+/////////////////////////////////////////////////////////////////////////
+/// This class provides functions to check whether an archive contains a
+/// valid Gnome-Pie theme.
+/////////////////////////////////////////////////////////////////////////
+
+public class ThemeImporter : ArchiveReader {
+
+ public bool is_valid_theme;
+ public string theme_name;
+
+ /////////////////////////////////////////////////////////////////////
+ /// Returns
+ /////////////////////////////////////////////////////////////////////
+
+ public new bool open(string path) {
+
+ this.is_valid_theme = false;
+ this.theme_name = "";
+
+ var tmp_reader = new ArchiveReader();
+
+ if (tmp_reader.open(path)) {
+ try {
+ var tmp_dir = GLib.DirUtils.make_tmp("gnomepieXXXXXX");
+ if (tmp_reader.extract_to(tmp_dir)) {
+ var tmp_theme = new Theme(tmp_dir);
+ if (tmp_theme.load()) {
+ is_valid_theme = true;
+ theme_name = tmp_theme.name;
+ }
+ }
+ } catch (Error e) {
+ warning(e.message);
+ }
+ }
+
+ tmp_reader.close();
+
+ return base.open(path);
+ }
+}
+
+}