[Cxplorer-cvs 00970] CVS update: cxplorer/src

Back to archive index

Yasumichi Akahoshi yasum****@users*****
2005年 4月 6日 (水) 20:05:58 JST


Index: cxplorer/src/cxp-property-dialog.c
diff -u /dev/null cxplorer/src/cxp-property-dialog.c:1.1
--- /dev/null	Wed Apr  6 20:05:58 2005
+++ cxplorer/src/cxp-property-dialog.c	Wed Apr  6 20:05:58 2005
@@ -0,0 +1,312 @@
+/**
+ * @file
+ * @brief A widget of Property dialog
+ *
+ * A widget of Property dialog
+ * @author Yasumichi Akahoshi <yasum****@users*****>
+ * @date Sun Apr 3 02:53:00 2005
+ * $Revision: 1.1 $
+ ****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <cxp.h>
+#include <glib/gi18n.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <grp.h>
+#include <pwd.h>
+#include "cxp-property-dialog.h"
+
+enum
+{
+	INFO_FILENAME = 0,
+	INFO_DIRECTORY,
+	INFO_SIZE,
+	INFO_OWNER,
+	INFO_GROUP,
+	INFO_LAST_STATUS_CHANGE,
+	INFO_LAST_MODIFICATION,
+	INFO_LAST_ACCESS,
+	INFO_COUNT,
+};
+
+/**
+ * the private structure 
+ */
+struct _CxpPropertyDialogPrivate
+{
+	gchar *filename;
+	GtkWidget *info_labels[INFO_COUNT];
+	gboolean dispose_has_run;
+};
+
+static GObjectClass *parent_class = NULL;
+
+enum
+{
+	CXP_PROPERTY_DIALOG_FILENAME = 1,
+};
+
+static void cxp_property_dialog_class_init (gpointer g_class,
+					    gpointer g_class_data);
+static void cxp_property_dialog_instance_init (GTypeInstance * instance,
+					       gpointer g_class);
+static void cxp_property_dialog_set_property (GObject * object,
+					      guint property_id,
+					      const GValue * value,
+					      GParamSpec * pspec);
+static void cxp_property_dialog_get_property (GObject * object,
+					      guint property_id, GValue * value,
+					      GParamSpec * pspec);
+static void cxp_property_dialog_dispose (GObject * obj);
+static void cxp_property_dialog_finalize (GObject * obj);
+static void cxp_property_dialog_set_values (CxpPropertyDialog *self);
+
+static void cxp_property_dialog_class_init (gpointer g_class,
+					    gpointer g_class_data)
+{
+	GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
+	CxpPropertyDialogClass *klass = CXP_PROPERTY_DIALOG_CLASS (g_class);
+	GParamSpec *pspec;
+
+	gobject_class->set_property = cxp_property_dialog_set_property;
+	gobject_class->get_property = cxp_property_dialog_get_property;
+	gobject_class->dispose = cxp_property_dialog_dispose;
+	gobject_class->finalize = cxp_property_dialog_finalize;
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	pspec = g_param_spec_string ("filename",
+			"CxpPropertyDialog construct prop",
+			"Set filename",
+			NULL,	
+			G_PARAM_READWRITE);
+	g_object_class_install_property (gobject_class,
+			CXP_PROPERTY_DIALOG_FILENAME,
+			pspec);
+}
+
+static void cxp_property_dialog_instance_init (GTypeInstance * instance,
+					       gpointer g_class)
+{
+	CxpPropertyDialog *self = CXP_PROPERTY_DIALOG (instance);
+	GtkWidget *close_button;
+	GtkWidget *table;
+	GtkWidget *title_label;
+	gchar *info_title[] = {
+		N_("Filename:"),
+		N_("Place:"),
+		N_("Size:"),
+		N_("Owner:"),
+		N_("Group:"),
+		N_("last status change:"),
+		N_("last modification:"),
+		N_("last access:")
+	};
+	gint index;
+
+	self->private = g_new (CxpPropertyDialogPrivate, 1);
+	self->private->filename = NULL;
+	self->private->dispose_has_run = FALSE;
+
+	gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
+	table = gtk_table_new(2, INFO_COUNT, FALSE);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self)->vbox), table, FALSE, FALSE, 0);
+	for(index=0; index<INFO_COUNT; index++)
+	{
+		title_label = gtk_label_new(_(info_title[index]));
+		gtk_misc_set_alignment (GTK_MISC(title_label), 1, 0);
+		gtk_table_attach (GTK_TABLE(table), title_label, 0, 1, index, index+1, GTK_FILL, 0, 2, 2);
+		gtk_widget_show (title_label);
+
+		self->private->info_labels[index] = gtk_label_new ("(null)");
+		gtk_misc_set_alignment (GTK_MISC(self->private->info_labels[index]), 0, 0);
+		gtk_table_attach (GTK_TABLE(table), self->private->info_labels[index], 1, 2, index, index+1, GTK_FILL, 0, 2, 2);
+		gtk_widget_show (self->private->info_labels[index]);
+	}
+	gtk_widget_show (table);
+
+	close_button = gtk_button_new_from_stock("gtk-close");
+	gtk_dialog_add_action_widget (GTK_DIALOG (self), close_button, GTK_RESPONSE_CLOSE);
+	gtk_widget_show (close_button);
+}
+
+static void cxp_property_dialog_set_property (GObject * object,
+					      guint property_id,
+					      const GValue * value,
+					      GParamSpec * pspec)
+{
+	CxpPropertyDialog *self = CXP_PROPERTY_DIALOG (object);
+
+	switch (property_id)
+	{
+	case CXP_PROPERTY_DIALOG_FILENAME:
+		if (self->private->filename != NULL)
+		{
+			g_free (self->private->filename);
+		}
+		self->private->filename = g_value_dup_string (value);
+		cxp_property_dialog_set_values (self);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+		break;
+	}
+}
+
+static void cxp_property_dialog_get_property (GObject * object,
+					      guint property_id, GValue * value,
+					      GParamSpec * pspec)
+{
+	CxpPropertyDialog *self = CXP_PROPERTY_DIALOG (object);
+
+	switch (property_id)
+	{
+	case CXP_PROPERTY_DIALOG_FILENAME:
+		g_value_set_string (value, self->private->filename);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+		break;
+	}
+}
+
+static void cxp_property_dialog_dispose (GObject * obj)
+{
+	CxpPropertyDialog *self = CXP_PROPERTY_DIALOG (obj);
+
+	if (self->private->dispose_has_run)
+	{
+		/* If dispose did already run, return. */
+		return;
+	}
+	/* Make sure dispose does not run twice. */
+	self->private->dispose_has_run = TRUE;
+
+	/* 
+	 * In dispose, you are supposed to free all types referenced from this
+	 * object which might themselves hold a reference to self. Generally,
+	 * the most simple solution is to unref all members on which you own a 
+	 * reference.
+	 */
+
+	/* Chain up to the parent class */
+	G_OBJECT_CLASS (parent_class)->dispose (obj);
+}
+
+static void cxp_property_dialog_finalize (GObject * obj)
+{
+	CxpPropertyDialog *self = CXP_PROPERTY_DIALOG (obj);
+
+	/*
+	 * Here, complete object destruction.
+	 * You might not need to do much...
+	 */
+
+	g_free (self->private);
+
+	/* Chain up to the parent class */
+	G_OBJECT_CLASS (parent_class)->finalize (obj);
+}
+
+GType cxp_property_dialog_get_type (void)
+{
+	static GType type = 0;
+
+	if (type == 0)
+	{
+		static const GTypeInfo info = {
+			sizeof (CxpPropertyDialogClass),
+			NULL,	/* base_init */
+			NULL,	/* base_finalize */
+			cxp_property_dialog_class_init,	/* class_init */
+			NULL,	/* class_finalize */
+			NULL,	/* class_data */
+			sizeof (CxpPropertyDialog),
+			0,	/* n_preallocs */
+			cxp_property_dialog_instance_init	/* instance_init */
+		};
+		type = g_type_register_static (GTK_TYPE_DIALOG,
+					       "CxpPropertyDialogType",
+					       &info, 0);
+	}
+	return type;
+}
+
+/**
+ * Creates a new dialog box which show detail of file.
+ */
+GtkWidget *cxp_property_dialog_new(const gchar *fullpath)
+{
+	CxpPropertyDialog *dialog;
+
+	dialog = g_object_new(CXP_TYPE_PROPERTY_DIALOG, NULL);
+	gtk_window_set_title(GTK_WINDOW(dialog), _("Property"));
+	g_object_set(dialog, "filename", fullpath, NULL);
+
+	return	GTK_WIDGET(dialog);
+}
+
+static void cxp_property_dialog_set_values (CxpPropertyDialog *self)
+{
+	gchar *filename = self->private->filename;
+	GtkWidget **labels = self->private->info_labels;
+	gchar *value;
+	struct stat status;
+	struct passwd *spasswd;
+	struct group *sgroup;
+
+	g_return_if_fail (filename != NULL);
+
+	stat (filename, &status);
+
+	value = cxp_path_get_basename_of_utf8(filename);
+	gtk_label_set_text(GTK_LABEL(labels[INFO_FILENAME]), value);
+	g_free (value);
+
+	value = cxp_path_get_dirname_of_utf8(filename);
+	gtk_label_set_text(GTK_LABEL(labels[INFO_DIRECTORY]), value);
+	g_free (value);
+
+	value = g_strdup_printf(_("%10ld bytes"), status.st_size);
+	gtk_label_set_text(GTK_LABEL(labels[INFO_SIZE]), value);
+	g_free (value);
+
+	if((spasswd = getpwuid (status.st_uid)) != NULL)
+	{
+		value = g_strdup (spasswd->pw_name);
+	}
+	else
+	{
+		value = g_strdup_printf("(uid)%d", status.st_uid);
+	}
+	gtk_label_set_text(GTK_LABEL(labels[INFO_OWNER]), value);
+	g_free (value);
+
+	if((sgroup = getgrgid (status.st_gid)) != NULL)
+	{
+		value = g_strdup (sgroup->gr_name);
+	}
+	else
+	{
+		value = g_strdup_printf("(gid)%d", status.st_gid);
+	}
+	gtk_label_set_text(GTK_LABEL(labels[INFO_GROUP]), value);
+	g_free (value);
+
+	value = cxp_strftime (&status.st_ctime);
+	gtk_label_set_text(GTK_LABEL(labels[INFO_LAST_STATUS_CHANGE]), value);
+	g_free (value);
+
+	value = cxp_strftime (&status.st_mtime);
+	gtk_label_set_text(GTK_LABEL(labels[INFO_LAST_MODIFICATION]), value);
+	g_free (value);
+
+	value = cxp_strftime (&status.st_atime);
+	gtk_label_set_text(GTK_LABEL(labels[INFO_LAST_ACCESS]), value);
+	g_free (value);
+}
Index: cxplorer/src/cxp-property-dialog.h
diff -u /dev/null cxplorer/src/cxp-property-dialog.h:1.1
--- /dev/null	Wed Apr  6 20:05:58 2005
+++ cxplorer/src/cxp-property-dialog.h	Wed Apr  6 20:05:58 2005
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ * Copyright/Licensing information.
+ */
+
+#ifndef CXP_PROPERTY_DIALOG_H
+#define CXP_PROPERTY_DIALOG_H
+
+/*
+ * Potentially, include other headers on which this header depends.
+ */
+#include <gtk/gtk.h>
+#include <glib-object.h>
+
+#define CXP_TYPE_PROPERTY_DIALOG		  (cxp_property_dialog_get_type ())
+#define CXP_PROPERTY_DIALOG(obj)		  (G_TYPE_CHECK_INSTANCE_CAST ((obj), CXP_TYPE_PROPERTY_DIALOG, CxpPropertyDialog))
+#define CXP_PROPERTY_DIALOG_CLASS(klass)	  (G_TYPE_CHECK_CLASS_CAST ((klass), CXP_TYPE_PROPERTY_DIALOG, CxpPropertyDialogClass))
+#define CXP_IS_PROPERTY_DIALOG(obj)	  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CXP_TYPE_PROPERTY_DIALOG))
+#define CXP_IS_PROPERTY_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CXP_TYPE_PROPERTY_DIALOG))
+#define CXP_PROPERTY_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CXP_TYPE_PROPERTY_DIALOG, CxpPropertyDialogClass))
+
+typedef struct _CxpPropertyDialog CxpPropertyDialog;
+typedef struct _CxpPropertyDialogClass CxpPropertyDialogClass;
+typedef struct _CxpPropertyDialogPrivate CxpPropertyDialogPrivate;
+
+struct _CxpPropertyDialog {
+	GtkDialog parent;
+	/* instance members */
+        CxpPropertyDialogPrivate *private;
+};
+
+struct _CxpPropertyDialogClass {
+	GtkDialogClass parent;
+
+	/* class members */
+};
+
+/* used by CXP_TYPE_PROPERTY_DIALOG */
+GType cxp_property_dialog_get_type (void);
+
+/* API. */
+GtkWidget *cxp_property_dialog_new(const gchar *fullpath);
+
+#endif /* CXP_PROPERTY_DIALOG_H */


Cxplorer-cvs メーリングリストの案内
Back to archive index