[gnome-format] Make it compile with Vala 0.6 and port the C parts to Vala
- From: Michael Kanis <mkanis src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-format] Make it compile with Vala 0.6 and port the C parts to Vala
- Date: Sat, 2 May 2009 04:14:00 -0400 (EDT)
commit 8aae51e35fdc3ec55ef99624df25c14bce56473c
Author: Michael Kanis <mkanis gmx de>
Date: Sat May 2 10:03:52 2009 +0200
Make it compile with Vala 0.6 and port the C parts to Vala
---
src/gnome-format-dialog.vala | 9 ++-
src/gnome-format-hal-storage-provider.vala | 30 ++++++++-
src/gnome-format-partition.c | 103 ----------------------------
src/gnome-format-partition.h | 21 ------
src/gnome-format-partitions.vala | 77 +++++++++++++++++++++
src/gnome-format-storage.vala | 27 -------
src/wscript_build | 2 +-
7 files changed, 111 insertions(+), 158 deletions(-)
diff --git a/src/gnome-format-dialog.vala b/src/gnome-format-dialog.vala
index 0d8fa58..3d278f1 100644
--- a/src/gnome-format-dialog.vala
+++ b/src/gnome-format-dialog.vala
@@ -168,7 +168,7 @@ namespace GnomeFormat {
/* signal callbacks */
/* ------------------------------------------------------------------ */
- public bool on_window_delete_event(Gtk.Window window) {
+ public bool on_window_delete_event(Gtk.Window window, Gdk.Event event) {
quit();
return true;
}
@@ -186,7 +186,7 @@ namespace GnomeFormat {
Storage s = storage_devices.get(volume_combo.get_active());
if (Config.DEBUG)
- debug(_("Formatting %s"), s.block_device);
+ debug("Formatting %s", s.block_device);
security_question_dialog.set_markup(_("<b>Really format \"%s\"?</b>").printf(s.model));
security_question_dialog.run();
@@ -208,13 +208,14 @@ namespace GnomeFormat {
string filesystem = filesystems[fs_type_combo.get_active()];
if (Config.DEBUG)
- debug(_("Creating partition on %s"), s.block_device);
+ debug("Creating partition on %s", s.block_device);
// i think, floppies don't have partition tables TODO: verify
if (s.drive_type != DriveType.floppy) {
// TODO make this threaded, so the GUI doesn't hang
try {
- create_partition(s.block_device, filesystem);
+ create_partition_2(s.block_device, filesystem);
+ debug("created partition");
} catch (GLib.Error e) {
message("%s", e.message);
error_dialog.set_markup(e.message);
diff --git a/src/gnome-format-hal-storage-provider.vala b/src/gnome-format-hal-storage-provider.vala
index 6e2e726..8ab5574 100644
--- a/src/gnome-format-hal-storage-provider.vala
+++ b/src/gnome-format-hal-storage-provider.vala
@@ -138,8 +138,8 @@ namespace GnomeFormat {
try {
s.udi = device.get_property_string("info.udi");
s.block_device = device.get_property_string("block.device");
- s.bus = Storage.get_bus_type(device.get_property_string("storage.bus"));
- s.drive_type = Storage.get_drive_type(
+ s.bus = get_bus_type(device.get_property_string("storage.bus"));
+ s.drive_type = get_drive_type(
device.get_property_string("storage.drive_type"));
s.removable = device.get_property_string("storage.removable");
s.hotpluggable = device.get_property_string("storage.hotpluggable");
@@ -163,6 +163,32 @@ namespace GnomeFormat {
return s;
}
+
+ // TODO complete bus types
+ public BusType get_bus_type(string s) throws StorageError {
+ if (s == "ide")
+ return BusType.ide;
+ else if (s == "usb")
+ return BusType.usb;
+ else if (s == "scsi")
+ return BusType.scsi;
+ else if (s == "mmc")
+ return BusType.mmc;
+ else
+ throw new StorageError.UNKNOWN_BUS("Unknown bus type \"%s\"", s);
+ }
+
+ // TODO complete drive types
+ public DriveType get_drive_type(string s) throws StorageError {
+ if (s == "disk")
+ return DriveType.disk;
+ else if (s == "cdrom")
+ return DriveType.cdrom;
+ else if (s == "sd_mmc")
+ return DriveType.sd_mmc;
+ else
+ throw new StorageError.UNKNOWN_DRIVE_TYPE("Unknown drive type \"%s\"", s);
+ }
}
}
diff --git a/src/gnome-format-partition.c b/src/gnome-format-partition.c
deleted file mode 100644
index 8ebafa6..0000000
--- a/src/gnome-format-partition.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright © 2008 Michael Kanis <mkanis gmx de>
- *
- * This file is part of Gnome Format.
- *
- * Gnome Format 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.
- *
- * Gnome Format 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 Gnome Format. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include <parted/parted.h>
-
-#include <config.h>
-
-#include "gnome-format-partition.h"
-
-#define try(exp) { \
- if(error_message) g_free(error_message); \
- (exp); \
- if (error_message) { \
- g_set_error(error, 0, -1, "%s", error_message); \
- return; \
- } \
- }
-
-
-gchar *error_message;
-
-PedExceptionOption
-parted_exception_handler(PedException* ex) {
- if(error_message) g_free(error_message);
- error_message = g_strdup(ex->message);
- return PED_EXCEPTION_OK;
-}
-
-void
-gnome_format_create_partition(gchar *block_dev, gchar *fs, GError **error) {
-
- PedDevice *device;
- PedDisk *disk;
- PedDiskType *label_type;
- PedFileSystemType *fs_type;
- PedPartition *part;
-
- ped_exception_set_handler(parted_exception_handler);
-
- try(device = ped_device_get(block_dev));
- disk = ped_disk_new(device);
-
- if (disk == NULL) {
- if(error_message) g_free(error_message);
- error_message = NULL;
- try(disk = ped_disk_new_fresh(device, ped_disk_type_get ("msdos")));
- }
-
- int last_part_num = ped_disk_get_last_partition_num(disk);
- if (last_part_num != -1) {
- // if partitions exist, delete them
- try(ped_disk_delete_all(disk));
- }
-
- long long end = device->length - 1;
-
- try(fs_type = ped_file_system_type_get(fs));
-
- // create new partition
- try(part = ped_partition_new(disk, PED_PARTITION_NORMAL, fs_type, 1, end));
- try(ped_disk_add_partition(disk, part, ped_constraint_any(device)));
-
- try(ped_file_system_create(&part->geom, fs_type, NULL));
-
- // commit changes
- try(ped_disk_commit_to_dev(disk));
-
- // this needs root priviliges
- try(ped_disk_commit_to_os(disk));
-
-#ifdef DEBUG
- printf("device.sector_size: %lld\n", device->sector_size);
- printf("device.length: %lld\n", device->length);
- printf("end: %lld\n", end);
-#endif
-
- // free stuff
- ped_disk_destroy(disk);
- ped_device_destroy(device);
-}
-
diff --git a/src/gnome-format-partition.h b/src/gnome-format-partition.h
deleted file mode 100644
index ae0f9d3..0000000
--- a/src/gnome-format-partition.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright © 2008 Michael Kanis <mkanis gmx de>
- *
- * This file is part of Gnome Format.
- *
- * Gnome Format 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.
- *
- * Gnome Format 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 Gnome Format. If not, see <http://www.gnu.org/licenses/>.
- */
-
-void gnome_format_create_partition(char *block_dev, char *fs, GError **error);
-
diff --git a/src/gnome-format-partitions.vala b/src/gnome-format-partitions.vala
new file mode 100644
index 0000000..e48e9f7
--- /dev/null
+++ b/src/gnome-format-partitions.vala
@@ -0,0 +1,77 @@
+/*
+ * Copyright © 2008 Michael Kanis <mkanis gmx de>
+ *
+ * This file is part of Gnome Format.
+ *
+ * Gnome Format 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.
+ *
+ * Gnome Format 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 Gnome Format. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using GLib;
+using Ped;
+
+
+/*
+PedExceptionOption
+parted_exception_handler(PedException* ex) {
+ if(error_message) g_free(error_message);
+ error_message = g_strdup(ex->message);
+ return PED_EXCEPTION_OK;
+}
+*/
+
+
+namespace GnomeFormat {
+ static void create_partition_2(string block_dev, string fs) {
+
+ DiskType label_type;
+
+// ped_exception_set_handler(parted_exception_handler);
+
+ Device device = new Device(block_dev);
+ Disk? disk = new Disk.from_device(device);
+
+ if (disk == null) {
+ disk = new Disk(device, new DiskType("msdos"));
+ }
+
+ int last_part_num = disk.get_last_partition_num();
+ if (last_part_num != -1) {
+ // if partitions exist, delete them
+ disk.delete_all();
+ }
+
+ Sector end = device.length - 1;
+
+ FileSystemType fs_type = new FileSystemType(fs);
+
+ // create new partition
+ Partition part = new Partition(disk,
+ Ped.PartitionType.NORMAL, fs_type, 1, end);
+
+ disk.add_partition(part, new Constraint.any(device));
+
+ new FileSystem.create(&part.geom, fs_type, null);
+
+ // commit changes
+ disk.commit_to_dev();
+
+ // this needs root priviliges
+ disk.commit_to_os();
+
+ debug("device.sector_size: %lld", device.sector_size);
+ debug("device.length: %lld", device.length);
+ debug("end: %lld", end);
+ }
+}
+
diff --git a/src/gnome-format-storage.vala b/src/gnome-format-storage.vala
index 95e7726..56d0ebd 100644
--- a/src/gnome-format-storage.vala
+++ b/src/gnome-format-storage.vala
@@ -57,33 +57,6 @@ namespace GnomeFormat {
public string model;
public string vendor;
- // TODO complete bus types
- public static BusType get_bus_type(string s) throws StorageError {
- if (s == "ide")
- return BusType.ide;
- else if (s == "usb")
- return BusType.usb;
- else if (s == "scsi")
- return BusType.scsi;
- else if (s == "mmc")
- return BusType.mmc;
- else
- throw new StorageError.UNKNOWN_BUS("Unknown bus type \"%s\"", s);
- }
-
- // TODO complete drive types
- public static DriveType get_drive_type(string s) throws StorageError {
- if (s == "disk")
- return DriveType.disk;
- else if (s == "cdrom")
- return DriveType.cdrom;
- else if (s == "sd_mmc")
- return DriveType.sd_mmc;
- else
- throw new StorageError.UNKNOWN_DRIVE_TYPE("Unknown drive type \"%s\"", s);
- }
-
-
public string get_readable_size() {
string[] size_units = new string[]
{"Byte", "KB", "MB", "GB", "TB", "PB"};
diff --git a/src/wscript_build b/src/wscript_build
index 5257e93..1e5de36 100644
--- a/src/wscript_build
+++ b/src/wscript_build
@@ -8,7 +8,7 @@ obj.find_sources_in_dirs('.') # take the sources in the current folder
obj.threading = True
obj.vapi_dirs = '../vapi'
obj.packages = 'gtk+-2.0 dbus-glib-1 gee-1.0 libglade-2.0 gmodule-2.0 ' \
- 'gio-unix-2.0 config partition'
+ 'gio-unix-2.0 config partition parted'
obj.target = 'gnome-format'
obj.uselib = 'GTK GLIB DBUS GEE GLADE GMODULE GIO_UNIX PARTED GTHREAD'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]