summaryrefslogtreecommitdiff
path: root/drivemount/drive-list.c
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2020-11-25 22:32:37 +0100
committerRobert Antoni Buj Gelonch <[email protected]>2020-11-27 21:23:07 +0100
commit48b8a559dfab8ea52a14d26bf54a8c93e0937101 (patch)
tree5a908fc4632975051f6e153f1e6f6d5198dd4622 /drivemount/drive-list.c
parent76fb110abce4f7337f06b16446c38fb8136c02d2 (diff)
downloadmate-applets-48b8a559dfab8ea52a14d26bf54a8c93e0937101.tar.bz2
mate-applets-48b8a559dfab8ea52a14d26bf54a8c93e0937101.tar.xz
drivemount: improve code-style
- tabs to spaces - 4 spaces at the beginning of a line
Diffstat (limited to 'drivemount/drive-list.c')
-rw-r--r--drivemount/drive-list.c384
1 files changed, 187 insertions, 197 deletions
diff --git a/drivemount/drive-list.c b/drivemount/drive-list.c
index 97e28573..b1840051 100644
--- a/drivemount/drive-list.c
+++ b/drivemount/drive-list.c
@@ -39,33 +39,18 @@ static void drive_list_dispose (GObject *object);
static void drive_list_add (GtkContainer *container, GtkWidget *child);
static void drive_list_remove (GtkContainer *container, GtkWidget *child);
-static void mount_added (GVolumeMonitor *monitor,
- GMount *mount,
- DriveList *self);
-static void mount_changed (GVolumeMonitor *monitor,
- GMount *mount,
- DriveList *self);
-static void mount_removed (GVolumeMonitor *monitor,
- GMount *mount,
- DriveList *self);
-static void volume_added (GVolumeMonitor *monitor,
- GVolume *volume,
- DriveList *self);
-static void volume_changed (GVolumeMonitor *monitor,
- GVolume *volume,
- DriveList *self);
-static void volume_removed (GVolumeMonitor *monitor,
- GVolume *volume,
- DriveList *self);
-static void add_volume (DriveList *self,
- GVolume *volume);
-static void remove_volume (DriveList *self,
- GVolume *volume);
-static void add_mount (DriveList *self,
- GMount *mount);
-static void remove_mount (DriveList *self,
- GMount *mount);
-static void queue_relayout (DriveList *self);
+static void mount_added (GVolumeMonitor *monitor, GMount *mount, DriveList *self);
+static void mount_changed (GVolumeMonitor *monitor, GMount *mount, DriveList *self);
+static void mount_removed (GVolumeMonitor *monitor, GMount *mount, DriveList *self);
+static void volume_added (GVolumeMonitor *monitor, GVolume *volume, DriveList *self);
+static void volume_changed (GVolumeMonitor *monitor, GVolume *volume, DriveList *self);
+static void volume_removed (GVolumeMonitor *monitor, GVolume *volume, DriveList *self);
+static void add_volume (DriveList *self, GVolume *volume);
+static void remove_volume (DriveList *self, GVolume *volume);
+static void add_mount (DriveList *self, GMount *mount);
+static void remove_mount (DriveList *self, GMount *mount);
+static void queue_relayout (DriveList *self);
+
static void
drive_list_class_init (DriveListClass *class)
{
@@ -91,57 +76,54 @@ drive_list_init (DriveList *self)
self->icon_size = 24;
self->relief = GTK_RELIEF_NORMAL;
- g_signal_connect(self->settings,
- "changed::drivemount-checkmark-color",
- G_CALLBACK (settings_color_changed),
- self);
+ g_signal_connect (self->settings,
+ "changed::drivemount-checkmark-color",
+ G_CALLBACK (settings_color_changed),
+ self);
/* listen for drive connects/disconnects, and add
* currently connected drives. */
- self->count = 0;
- if (!volume_monitor)
- volume_monitor = g_volume_monitor_get ();
+ self->count = 0;
+ if (!volume_monitor)
+ volume_monitor = g_volume_monitor_get ();
g_signal_connect_object (volume_monitor, "mount_added",
- G_CALLBACK (mount_added), self, 0);
+ G_CALLBACK (mount_added), self, 0);
g_signal_connect_object (volume_monitor, "mount_changed",
- G_CALLBACK (mount_changed), self, 0);
+ G_CALLBACK (mount_changed), self, 0);
g_signal_connect_object (volume_monitor, "mount_removed",
- G_CALLBACK (mount_removed), self, 0);
+ G_CALLBACK (mount_removed), self, 0);
g_signal_connect_object (volume_monitor, "volume_added",
- G_CALLBACK (volume_added), self, 0);
+ G_CALLBACK (volume_added), self, 0);
g_signal_connect_object (volume_monitor, "volume_changed",
- G_CALLBACK (volume_changed), self, 0);
+ G_CALLBACK (volume_changed), self, 0);
g_signal_connect_object (volume_monitor, "volume_removed",
- G_CALLBACK (volume_removed), self, 0);
- volumes = g_volume_monitor_get_volumes (volume_monitor);
- for (tmp = volumes; tmp != NULL; tmp = tmp->next)
- {
- GVolume *volume = tmp->data;
- add_volume (self, volume);
- g_object_unref (volume);
- self->count++;
- }
- g_list_free (volumes);
-
- mounts = g_volume_monitor_get_mounts (volume_monitor);
- for (tmp = mounts; tmp != NULL; tmp = tmp->next)
- {
- GMount *mount = tmp->data;
- add_mount (self, mount);
- g_object_unref (mount);
- self->count++;
- }
- self->dummy = drive_button_new (NULL);
- gtk_button_set_relief (GTK_BUTTON (self->dummy), self->relief);
- drive_button_set_size (DRIVE_BUTTON (self->dummy), self->icon_size);
-
- if (self->count == 0)
- {
- gtk_container_add (GTK_CONTAINER (self), self->dummy);
- queue_relayout (self);
- drive_button_queue_update (DRIVE_BUTTON (self->dummy));
- }
+ G_CALLBACK (volume_removed), self, 0);
+ volumes = g_volume_monitor_get_volumes (volume_monitor);
+ for (tmp = volumes; tmp != NULL; tmp = tmp->next) {
+ GVolume *volume = tmp->data;
+ add_volume (self, volume);
+ g_object_unref (volume);
+ self->count++;
+ }
+ g_list_free (volumes);
+
+ mounts = g_volume_monitor_get_mounts (volume_monitor);
+ for (tmp = mounts; tmp != NULL; tmp = tmp->next) {
+ GMount *mount = tmp->data;
+ add_mount (self, mount);
+ g_object_unref (mount);
+ self->count++;
+ }
+ self->dummy = drive_button_new (NULL);
+ gtk_button_set_relief (GTK_BUTTON (self->dummy), self->relief);
+ drive_button_set_size (DRIVE_BUTTON (self->dummy), self->icon_size);
+
+ if (self->count == 0) {
+ gtk_container_add (GTK_CONTAINER (self), self->dummy);
+ queue_relayout (self);
+ drive_button_queue_update (DRIVE_BUTTON (self->dummy));
+ }
g_list_free (mounts);
}
@@ -161,7 +143,7 @@ drive_list_finalize (GObject *object)
g_object_unref (self->settings);
if (G_OBJECT_CLASS (drive_list_parent_class)->finalize)
- (* G_OBJECT_CLASS (drive_list_parent_class)->finalize) (object);
+ (* G_OBJECT_CLASS (drive_list_parent_class)->finalize) (object);
}
static void
@@ -170,28 +152,29 @@ drive_list_dispose (GObject *object)
DriveList *self = DRIVE_LIST (object);
g_signal_handlers_disconnect_by_func (volume_monitor,
- G_CALLBACK (mount_added), self);
+ G_CALLBACK (mount_added), self);
g_signal_handlers_disconnect_by_func (volume_monitor,
- G_CALLBACK (mount_changed), self);
+ G_CALLBACK (mount_changed), self);
g_signal_handlers_disconnect_by_func (volume_monitor,
- G_CALLBACK (mount_removed), self);
+ G_CALLBACK (mount_removed), self);
g_signal_handlers_disconnect_by_func (volume_monitor,
- G_CALLBACK (volume_added), self);
+ G_CALLBACK (volume_added), self);
g_signal_handlers_disconnect_by_func (volume_monitor,
- G_CALLBACK (volume_changed), self);
+ G_CALLBACK (volume_changed), self);
g_signal_handlers_disconnect_by_func (volume_monitor,
- G_CALLBACK (volume_removed), self);
+ G_CALLBACK (volume_removed), self);
if (self->layout_tag)
- g_source_remove (self->layout_tag);
+ g_source_remove (self->layout_tag);
self->layout_tag = 0;
if (G_OBJECT_CLASS (drive_list_parent_class)->dispose)
- (* G_OBJECT_CLASS (drive_list_parent_class)->dispose) (object);
+ (* G_OBJECT_CLASS (drive_list_parent_class)->dispose) (object);
}
static void
-drive_list_add (GtkContainer *container, GtkWidget *child)
+drive_list_add (GtkContainer *container,
+ GtkWidget *child)
{
DriveList *self;
DriveButton *button;
@@ -200,19 +183,19 @@ drive_list_add (GtkContainer *container, GtkWidget *child)
g_return_if_fail (DRIVE_IS_BUTTON (child));
if (GTK_CONTAINER_CLASS (drive_list_parent_class)->add)
- (* GTK_CONTAINER_CLASS (drive_list_parent_class)->add) (container,
- child);
+ (* GTK_CONTAINER_CLASS (drive_list_parent_class)->add) (container, child);
self = DRIVE_LIST (container);
button = DRIVE_BUTTON (child);
if (button->volume)
- g_hash_table_insert (self->volumes, button->volume, button);
+ g_hash_table_insert (self->volumes, button->volume, button);
else
- g_hash_table_insert (self->mounts, button->mount, button);
+ g_hash_table_insert (self->mounts, button->mount, button);
}
static void
-drive_list_remove (GtkContainer *container, GtkWidget *child)
+drive_list_remove (GtkContainer *container,
+ GtkWidget *child)
{
DriveList *self;
DriveButton *button;
@@ -223,177 +206,173 @@ drive_list_remove (GtkContainer *container, GtkWidget *child)
self = DRIVE_LIST (container);
button = DRIVE_BUTTON (child);
if (button->volume)
- g_hash_table_remove (self->volumes, button->volume);
+ g_hash_table_remove (self->volumes, button->volume);
else
- g_hash_table_remove (self->mounts, button->mount);
+ g_hash_table_remove (self->mounts, button->mount);
if (GTK_CONTAINER_CLASS (drive_list_parent_class)->remove)
- (* GTK_CONTAINER_CLASS (drive_list_parent_class)->remove) (container,
- child);
+ (* GTK_CONTAINER_CLASS (drive_list_parent_class)->remove) (container, child);
}
static void
-list_buttons (gpointer key, gpointer value, gpointer user_data)
+list_buttons (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
GtkWidget *button = value;
GList **sorted_buttons = user_data;
*sorted_buttons = g_list_insert_sorted (*sorted_buttons, button,
- (GCompareFunc)drive_button_compare);
+ (GCompareFunc)drive_button_compare);
}
static gboolean
relayout_buttons (gpointer data)
{
- DriveList *self = DRIVE_LIST (data);
- GList *sorted_buttons = NULL, *tmp;
- int i = 0;
-
-
- self->layout_tag = 0;
- if ( self->count > 0 )
- {
- g_hash_table_foreach (self->volumes, list_buttons, &sorted_buttons);
- g_hash_table_foreach (self->mounts, list_buttons, &sorted_buttons);
-
- /* position buttons in the table according to their sorted order */
- for (tmp = sorted_buttons, i = 0; tmp != NULL; tmp = tmp->next, i++)
- {
- GtkWidget *button = tmp->data;
-
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
- gtk_container_child_set (GTK_CONTAINER (self), button,
- "left-attach", i + 1, "top-attach", 0,
- "width", 1, "height", 1,
- NULL);
- }
- else
- {
- gtk_container_child_set (GTK_CONTAINER (self), button,
- "left-attach", 0, "top-attach", i + 1,
- "width", 1, "height", 1,
- NULL);
- }
- }
- }
- else
- {
- gtk_widget_show (self->dummy);
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- gtk_container_child_set (GTK_CONTAINER (self), self->dummy,
- "left-attach", i + 1, "top-attach", 0,
- "width", 1, "height", 1,
- NULL);
- }
- else
- {
- gtk_container_child_set (GTK_CONTAINER (self), self->dummy,
- "left-attach", 0, "top-attach", i + 1,
- "width", 1, "height", 1,
- NULL);
- }
- }
- return FALSE;
+ DriveList *self = DRIVE_LIST (data);
+ GList *sorted_buttons = NULL, *tmp;
+ int i = 0;
+
+ self->layout_tag = 0;
+ if ( self->count > 0 ) {
+ g_hash_table_foreach (self->volumes, list_buttons, &sorted_buttons);
+ g_hash_table_foreach (self->mounts, list_buttons, &sorted_buttons);
+
+ /* position buttons in the table according to their sorted order */
+ for (tmp = sorted_buttons, i = 0; tmp != NULL; tmp = tmp->next, i++) {
+ GtkWidget *button = tmp->data;
+
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ gtk_container_child_set (GTK_CONTAINER (self), button,
+ "left-attach", i + 1, "top-attach", 0,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ else {
+ gtk_container_child_set (GTK_CONTAINER (self), button,
+ "left-attach", 0, "top-attach", i + 1,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ }
+ }
+ else {
+ gtk_widget_show (self->dummy);
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ gtk_container_child_set (GTK_CONTAINER (self), self->dummy,
+ "left-attach", i + 1, "top-attach", 0,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ else {
+ gtk_container_child_set (GTK_CONTAINER (self), self->dummy,
+ "left-attach", 0, "top-attach", i + 1,
+ "width", 1, "height", 1,
+ NULL);
+ }
+ }
+ return FALSE;
}
static void
queue_relayout (DriveList *self)
{
if (!self->layout_tag) {
- self->layout_tag = g_idle_add (relayout_buttons, self);
+ self->layout_tag = g_idle_add (relayout_buttons, self);
}
}
static void
mount_added (GVolumeMonitor *monitor,
- GMount *mount,
- DriveList *self)
+ GMount *mount,
+ DriveList *self)
{
add_mount (self, mount);
- self->count++;
- if (self->count == 1)
- gtk_container_remove (GTK_CONTAINER (self), g_object_ref(self->dummy));
+ self->count++;
+ if (self->count == 1)
+ gtk_container_remove (GTK_CONTAINER (self), g_object_ref (self->dummy));
+
mount_changed (monitor, mount, self);
}
static void
mount_changed (GVolumeMonitor *monitor,
- GMount *mount,
- DriveList *self)
+ GMount *mount,
+ DriveList *self)
{
GVolume *volume;
DriveButton *button = NULL;;
volume = g_mount_get_volume (mount);
if (volume) {
- button = g_hash_table_lookup (self->volumes, volume);
- g_object_unref (volume);
+ button = g_hash_table_lookup (self->volumes, volume);
+ g_object_unref (volume);
} else {
- button = g_hash_table_lookup (self->mounts, mount);
+ button = g_hash_table_lookup (self->mounts, mount);
}
if (button)
- drive_button_queue_update (button);
+ drive_button_queue_update (button);
}
static void
mount_removed (GVolumeMonitor *monitor,
- GMount *mount,
- DriveList *self)
+ GMount *mount,
+ DriveList *self)
{
remove_mount (self, mount);
mount_changed (monitor, mount, self);
- self->count--;
- if (self->count == 0) {
- gtk_container_add (GTK_CONTAINER (self), self->dummy);
- queue_relayout(self);
- }
+ self->count--;
+ if (self->count == 0) {
+ gtk_container_add (GTK_CONTAINER (self), self->dummy);
+ queue_relayout (self);
+ }
}
static void
volume_added (GVolumeMonitor *monitor,
- GVolume *volume,
- DriveList *self)
+ GVolume *volume,
+ DriveList *self)
{
add_volume (self, volume);
- self->count++;
- if (self->count == 1)
- gtk_container_remove (GTK_CONTAINER (self), g_object_ref(self->dummy));
+ self->count++;
+ if (self->count == 1)
+ gtk_container_remove (GTK_CONTAINER (self), g_object_ref (self->dummy));
}
static void
volume_changed (GVolumeMonitor *monitor,
- GVolume *volume,
- DriveList *self)
+ GVolume *volume,
+ DriveList *self)
{
DriveButton *button = NULL;;
button = g_hash_table_lookup (self->volumes, volume);
if (button)
- drive_button_queue_update (button);
+ drive_button_queue_update (button);
}
static void
volume_removed (GVolumeMonitor *monitor,
- GVolume *volume,
- DriveList *self)
+ GVolume *volume,
+ DriveList *self)
{
remove_volume (self, volume);
- self->count--;
- if (self->count == 0) {
- gtk_container_add (GTK_CONTAINER (self), self->dummy);
- queue_relayout(self);
- }
+ self->count--;
+ if (self->count == 0) {
+ gtk_container_add (GTK_CONTAINER (self), self->dummy);
+ queue_relayout (self);
+ }
}
static void
-add_volume (DriveList *self, GVolume *volume)
+add_volume (DriveList *self,
+ GVolume *volume)
{
GtkWidget *button;
/* if the volume has already been added, return */
if (g_hash_table_lookup (self->volumes, volume) != NULL)
- return;
+ return;
button = drive_button_new (volume);
gtk_button_set_relief (GTK_BUTTON (button), self->relief);
@@ -404,20 +383,22 @@ add_volume (DriveList *self, GVolume *volume)
}
static void
-remove_volume (DriveList *self, GVolume *volume)
+remove_volume (DriveList *self,
+ GVolume *volume)
{
GtkWidget *button;
/* if the volume has already been added, return */
button = g_hash_table_lookup (self->volumes, volume);
if (button) {
- gtk_container_remove (GTK_CONTAINER (self), button);
- queue_relayout (self);
+ gtk_container_remove (GTK_CONTAINER (self), button);
+ queue_relayout (self);
}
}
static void
-add_mount (DriveList *self, GMount *mount)
+add_mount (DriveList *self,
+ GMount *mount)
{
GtkWidget *button;
GVolume *volume;
@@ -430,13 +411,13 @@ add_mount (DriveList *self, GMount *mount)
/* ignore mounts attached to a volume */
volume = g_mount_get_volume (mount);
if (volume) {
- g_object_unref (volume);
- return;
+ g_object_unref (volume);
+ return;
}
/* if the mount has already been added, return */
if (g_hash_table_lookup (self->mounts, mount) != NULL)
- return;
+ return;
button = drive_button_new_from_mount (mount);
gtk_button_set_relief (GTK_BUTTON (button), self->relief);
@@ -447,32 +428,35 @@ add_mount (DriveList *self, GMount *mount)
}
static void
-remove_mount (DriveList *self, GMount *mount)
+remove_mount (DriveList *self,
+ GMount *mount)
{
GtkWidget *button;
/* if the mount has already been added, return */
button = g_hash_table_lookup (self->mounts, mount);
if (button) {
- gtk_container_remove (GTK_CONTAINER (self), button);
- queue_relayout (self);
+ gtk_container_remove (GTK_CONTAINER (self), button);
+ queue_relayout (self);
}
}
void
-drive_list_set_orientation (DriveList *self,
- GtkOrientation orientation)
+drive_list_set_orientation (DriveList *self,
+ GtkOrientation orientation)
{
g_return_if_fail (DRIVE_IS_LIST (self));
if (orientation != self->orientation) {
- self->orientation = orientation;
- queue_relayout (self);
+ self->orientation = orientation;
+ queue_relayout (self);
}
}
static void
-set_icon_size (gpointer key, gpointer value, gpointer user_data)
+set_icon_size (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
DriveButton *button = value;
DriveList *self = user_data;
@@ -482,14 +466,15 @@ set_icon_size (gpointer key, gpointer value, gpointer user_data)
void
-drive_list_set_panel_size (DriveList *self, int panel_size)
+drive_list_set_panel_size (DriveList *self,
+ int panel_size)
{
g_return_if_fail (DRIVE_IS_LIST (self));
if (self->icon_size != panel_size) {
- self->icon_size = panel_size;
- g_hash_table_foreach (self->volumes, set_icon_size, self);
- g_hash_table_foreach (self->mounts, set_icon_size, self);
+ self->icon_size = panel_size;
+ g_hash_table_foreach (self->volumes, set_icon_size, self);
+ g_hash_table_foreach (self->mounts, set_icon_size, self);
}
}
@@ -501,14 +486,18 @@ drive_list_redraw (DriveList *self)
}
void
-settings_color_changed (GSettings *settings, gchar *key, DriveList *drive_list)
+settings_color_changed (GSettings *settings,
+ gchar *key,
+ DriveList *drive_list)
{
g_return_if_fail (DRIVE_IS_LIST (drive_list));
drive_list_redraw (drive_list);
}
static void
-set_button_relief (gpointer key, gpointer value, gpointer user_data)
+set_button_relief (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
GtkButton *button = value;
DriveList *self = user_data;
@@ -517,7 +506,8 @@ set_button_relief (gpointer key, gpointer value, gpointer user_data)
}
void
-drive_list_set_transparent (DriveList *self, gboolean transparent)
+drive_list_set_transparent (DriveList *self,
+ gboolean transparent)
{
GtkReliefStyle relief;