The properties plug-in is now useful

This commit is contained in:
Pierre Pronchery 2011-07-19 02:55:38 +00:00
parent b23aab233e
commit fd8494e117
10 changed files with 442 additions and 354 deletions

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Browser 0.1.4\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-07-19 02:07+0200\n"
"POT-Creation-Date: 2011-07-19 04:54+0200\n"
"PO-Revision-Date: 2010-03-29 23:28+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: English\n"
@ -145,7 +145,7 @@ msgstr ""
msgid "Paste"
msgstr ""
#: ../src/browser.c:197 ../src/plugins/properties.c:43
#: ../src/browser.c:197 ../src/plugins/properties.c:39
msgid "Properties"
msgstr "Eigenschaften"
@ -188,7 +188,7 @@ msgstr ""
#: ../src/browser.c:700 ../src/browser.c:705 ../src/copy.c:674
#: ../src/copy.c:678 ../src/delete.c:421 ../src/delete.c:426
#: ../src/desktop.c:1647 ../src/desktop.c:1652 ../src/move.c:452
#: ../src/move.c:456 ../src/properties.c:118 ../src/properties.c:122
#: ../src/move.c:456 ../src/properties.c:291 ../src/properties.c:295
#: ../src/view.c:367 ../src/view.c:372
msgid "Error"
msgstr "Fehler"
@ -412,7 +412,7 @@ msgstr ""
msgid "Omitting directory"
msgstr ""
#: ../src/copy.c:590 ../src/properties.c:480
#: ../src/copy.c:590 ../src/properties.c:497
msgid "kB"
msgstr ""
@ -420,7 +420,7 @@ msgstr ""
msgid "0.0 kB/s"
msgstr ""
#: ../src/copy.c:615 ../src/properties.c:482
#: ../src/copy.c:615 ../src/properties.c:499
msgid "MB"
msgstr ""
@ -606,67 +606,71 @@ msgid ""
" -a\taction to call (default: \"open\")\n"
msgstr ""
#: ../src/properties.c:237
msgid "Properties of "
msgstr "Eigenschaften von "
#: ../src/properties.c:262
#: ../src/properties.c:170
msgid "Size:"
msgstr "Größe:"
#: ../src/properties.c:268 ../src/properties.c:318
#: ../src/properties.c:176 ../src/properties.c:224
msgid "Owner:"
msgstr ""
#: ../src/properties.c:274 ../src/properties.c:321
#: ../src/properties.c:182 ../src/properties.c:227
msgid "Group:"
msgstr "Gruppe:"
#: ../src/properties.c:282
#: ../src/properties.c:188
msgid "Accessed:"
msgstr ""
#: ../src/properties.c:288
#: ../src/properties.c:194
msgid "Modified:"
msgstr ""
#: ../src/properties.c:294
#: ../src/properties.c:200
msgid "Changed:"
msgstr ""
#: ../src/properties.c:300
#: ../src/properties.c:206
msgid "Permissions:"
msgstr ""
#: ../src/properties.c:324
#: ../src/properties.c:230
msgid "Others:"
msgstr ""
#: ../src/properties.c:443
#: ../src/properties.c:408
msgid "Unknown type"
msgstr ""
#: ../src/properties.c:427
msgid "read"
msgstr ""
#: ../src/properties.c:447
#: ../src/properties.c:431
msgid "write"
msgstr ""
#: ../src/properties.c:451
#: ../src/properties.c:435
msgid "execute"
msgstr ""
#: ../src/properties.c:474
#: ../src/properties.c:491
msgid "bytes"
msgstr ""
#: ../src/properties.c:484
#: ../src/properties.c:501
msgid "GB"
msgstr ""
#: ../src/properties.c:488
#: ../src/properties.c:505
msgid "TB"
msgstr ""
#: ../src/properties.c:560
#: ../src/properties.c:541
msgid "Properties of "
msgstr "Eigenschaften von "
#: ../src/properties.c:627
msgid "Usage: properties file...\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Browser 0.1.4\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-07-19 02:07+0200\n"
"POT-Creation-Date: 2011-07-19 04:54+0200\n"
"PO-Revision-Date: 2010-03-30 01:04+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: Spanish\n"
@ -145,7 +145,7 @@ msgstr ""
msgid "Paste"
msgstr ""
#: ../src/browser.c:197 ../src/plugins/properties.c:43
#: ../src/browser.c:197 ../src/plugins/properties.c:39
msgid "Properties"
msgstr "Propriedades"
@ -188,7 +188,7 @@ msgstr ""
#: ../src/browser.c:700 ../src/browser.c:705 ../src/copy.c:674
#: ../src/copy.c:678 ../src/delete.c:421 ../src/delete.c:426
#: ../src/desktop.c:1647 ../src/desktop.c:1652 ../src/move.c:452
#: ../src/move.c:456 ../src/properties.c:118 ../src/properties.c:122
#: ../src/move.c:456 ../src/properties.c:291 ../src/properties.c:295
#: ../src/view.c:367 ../src/view.c:372
msgid "Error"
msgstr ""
@ -412,7 +412,7 @@ msgstr ""
msgid "Omitting directory"
msgstr ""
#: ../src/copy.c:590 ../src/properties.c:480
#: ../src/copy.c:590 ../src/properties.c:497
msgid "kB"
msgstr ""
@ -420,7 +420,7 @@ msgstr ""
msgid "0.0 kB/s"
msgstr ""
#: ../src/copy.c:615 ../src/properties.c:482
#: ../src/copy.c:615 ../src/properties.c:499
msgid "MB"
msgstr ""
@ -606,67 +606,71 @@ msgid ""
" -a\taction to call (default: \"open\")\n"
msgstr ""
#: ../src/properties.c:237
msgid "Properties of "
msgstr "Propriedades con "
#: ../src/properties.c:262
#: ../src/properties.c:170
msgid "Size:"
msgstr ""
#: ../src/properties.c:268 ../src/properties.c:318
#: ../src/properties.c:176 ../src/properties.c:224
msgid "Owner:"
msgstr ""
#: ../src/properties.c:274 ../src/properties.c:321
#: ../src/properties.c:182 ../src/properties.c:227
msgid "Group:"
msgstr ""
#: ../src/properties.c:282
#: ../src/properties.c:188
msgid "Accessed:"
msgstr ""
#: ../src/properties.c:288
#: ../src/properties.c:194
msgid "Modified:"
msgstr ""
#: ../src/properties.c:294
#: ../src/properties.c:200
msgid "Changed:"
msgstr ""
#: ../src/properties.c:300
#: ../src/properties.c:206
msgid "Permissions:"
msgstr ""
#: ../src/properties.c:324
#: ../src/properties.c:230
msgid "Others:"
msgstr ""
#: ../src/properties.c:443
#: ../src/properties.c:408
msgid "Unknown type"
msgstr ""
#: ../src/properties.c:427
msgid "read"
msgstr ""
#: ../src/properties.c:447
#: ../src/properties.c:431
msgid "write"
msgstr ""
#: ../src/properties.c:451
#: ../src/properties.c:435
msgid "execute"
msgstr ""
#: ../src/properties.c:474
#: ../src/properties.c:491
msgid "bytes"
msgstr ""
#: ../src/properties.c:484
#: ../src/properties.c:501
msgid "GB"
msgstr ""
#: ../src/properties.c:488
#: ../src/properties.c:505
msgid "TB"
msgstr ""
#: ../src/properties.c:560
#: ../src/properties.c:541
msgid "Properties of "
msgstr "Propriedades con "
#: ../src/properties.c:627
msgid "Usage: properties file...\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Browser 0.1.4\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-07-19 02:07+0200\n"
"POT-Creation-Date: 2011-07-19 04:54+0200\n"
"PO-Revision-Date: 2010-03-29 23:28+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: French\n"
@ -145,7 +145,7 @@ msgstr "Copier"
msgid "Paste"
msgstr "Coller"
#: ../src/browser.c:197 ../src/plugins/properties.c:43
#: ../src/browser.c:197 ../src/plugins/properties.c:39
msgid "Properties"
msgstr "Propriétés"
@ -188,7 +188,7 @@ msgstr " Chemin : "
#: ../src/browser.c:700 ../src/browser.c:705 ../src/copy.c:674
#: ../src/copy.c:678 ../src/delete.c:421 ../src/delete.c:426
#: ../src/desktop.c:1647 ../src/desktop.c:1652 ../src/move.c:452
#: ../src/move.c:456 ../src/properties.c:118 ../src/properties.c:122
#: ../src/move.c:456 ../src/properties.c:291 ../src/properties.c:295
#: ../src/view.c:367 ../src/view.c:372
msgid "Error"
msgstr "Erreur"
@ -412,7 +412,7 @@ msgstr "Fichier %u sur %u"
msgid "Omitting directory"
msgstr "Omission du dossier"
#: ../src/copy.c:590 ../src/properties.c:480
#: ../src/copy.c:590 ../src/properties.c:497
msgid "kB"
msgstr "Kio"
@ -420,7 +420,7 @@ msgstr "Kio"
msgid "0.0 kB/s"
msgstr "0.0 Kio/s"
#: ../src/copy.c:615 ../src/properties.c:482
#: ../src/copy.c:615 ../src/properties.c:499
msgid "MB"
msgstr "Mio"
@ -640,67 +640,71 @@ msgstr ""
" -m\tType MIME à forcer (défaut: auto-détecté)\n"
" -a\taction à appeler (défaut: \"open\")\n"
#: ../src/properties.c:237
msgid "Properties of "
msgstr "Propriétés de "
#: ../src/properties.c:262
#: ../src/properties.c:170
msgid "Size:"
msgstr "Taille:"
#: ../src/properties.c:268 ../src/properties.c:318
#: ../src/properties.c:176 ../src/properties.c:224
msgid "Owner:"
msgstr "Propriétaire:"
#: ../src/properties.c:274 ../src/properties.c:321
#: ../src/properties.c:182 ../src/properties.c:227
msgid "Group:"
msgstr "Groupe:"
#: ../src/properties.c:282
#: ../src/properties.c:188
msgid "Accessed:"
msgstr "Accédé:"
#: ../src/properties.c:288
#: ../src/properties.c:194
msgid "Modified:"
msgstr "Modifié:"
#: ../src/properties.c:294
#: ../src/properties.c:200
msgid "Changed:"
msgstr "Changé:"
#: ../src/properties.c:300
#: ../src/properties.c:206
msgid "Permissions:"
msgstr "Permissions:"
#: ../src/properties.c:324
#: ../src/properties.c:230
msgid "Others:"
msgstr "Autres:"
#: ../src/properties.c:443
#: ../src/properties.c:408
msgid "Unknown type"
msgstr "Type de fichier inconnu"
#: ../src/properties.c:427
msgid "read"
msgstr "lecture"
#: ../src/properties.c:447
#: ../src/properties.c:431
msgid "write"
msgstr "écriture"
#: ../src/properties.c:451
#: ../src/properties.c:435
msgid "execute"
msgstr "exécution"
#: ../src/properties.c:474
#: ../src/properties.c:491
msgid "bytes"
msgstr "octets"
#: ../src/properties.c:484
#: ../src/properties.c:501
msgid "GB"
msgstr "Gio"
#: ../src/properties.c:488
#: ../src/properties.c:505
msgid "TB"
msgstr "Tio"
#: ../src/properties.c:560
#: ../src/properties.c:541
msgid "Properties of "
msgstr "Propriétés de "
#: ../src/properties.c:627
msgid "Usage: properties file...\n"
msgstr "Usage: properties fichier...\n"
@ -738,7 +742,7 @@ msgstr "Usage: view fichier...\n"
#: ../src/plugins/devices.c:76
msgid "Devices"
msgstr "Montages"
msgstr "Périphériques"
#: ../src/plugins/devices.c:207
msgid "Root filesystem"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Browser 0.1.4\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-07-19 02:07+0200\n"
"POT-Creation-Date: 2011-07-19 04:54+0200\n"
"PO-Revision-Date: 2010-04-07 23:18+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: Italian\n"
@ -145,7 +145,7 @@ msgstr ""
msgid "Paste"
msgstr ""
#: ../src/browser.c:197 ../src/plugins/properties.c:43
#: ../src/browser.c:197 ../src/plugins/properties.c:39
msgid "Properties"
msgstr ""
@ -188,7 +188,7 @@ msgstr ""
#: ../src/browser.c:700 ../src/browser.c:705 ../src/copy.c:674
#: ../src/copy.c:678 ../src/delete.c:421 ../src/delete.c:426
#: ../src/desktop.c:1647 ../src/desktop.c:1652 ../src/move.c:452
#: ../src/move.c:456 ../src/properties.c:118 ../src/properties.c:122
#: ../src/move.c:456 ../src/properties.c:291 ../src/properties.c:295
#: ../src/view.c:367 ../src/view.c:372
msgid "Error"
msgstr ""
@ -412,7 +412,7 @@ msgstr ""
msgid "Omitting directory"
msgstr ""
#: ../src/copy.c:590 ../src/properties.c:480
#: ../src/copy.c:590 ../src/properties.c:497
msgid "kB"
msgstr ""
@ -420,7 +420,7 @@ msgstr ""
msgid "0.0 kB/s"
msgstr ""
#: ../src/copy.c:615 ../src/properties.c:482
#: ../src/copy.c:615 ../src/properties.c:499
msgid "MB"
msgstr ""
@ -606,67 +606,71 @@ msgid ""
" -a\taction to call (default: \"open\")\n"
msgstr ""
#: ../src/properties.c:237
msgid "Properties of "
msgstr ""
#: ../src/properties.c:262
#: ../src/properties.c:170
msgid "Size:"
msgstr ""
#: ../src/properties.c:268 ../src/properties.c:318
#: ../src/properties.c:176 ../src/properties.c:224
msgid "Owner:"
msgstr ""
#: ../src/properties.c:274 ../src/properties.c:321
#: ../src/properties.c:182 ../src/properties.c:227
msgid "Group:"
msgstr ""
#: ../src/properties.c:282
#: ../src/properties.c:188
msgid "Accessed:"
msgstr ""
#: ../src/properties.c:288
#: ../src/properties.c:194
msgid "Modified:"
msgstr ""
#: ../src/properties.c:294
#: ../src/properties.c:200
msgid "Changed:"
msgstr ""
#: ../src/properties.c:300
#: ../src/properties.c:206
msgid "Permissions:"
msgstr ""
#: ../src/properties.c:324
#: ../src/properties.c:230
msgid "Others:"
msgstr ""
#: ../src/properties.c:443
#: ../src/properties.c:408
msgid "Unknown type"
msgstr ""
#: ../src/properties.c:427
msgid "read"
msgstr ""
#: ../src/properties.c:447
#: ../src/properties.c:431
msgid "write"
msgstr ""
#: ../src/properties.c:451
#: ../src/properties.c:435
msgid "execute"
msgstr ""
#: ../src/properties.c:474
#: ../src/properties.c:491
msgid "bytes"
msgstr ""
#: ../src/properties.c:484
#: ../src/properties.c:501
msgid "GB"
msgstr ""
#: ../src/properties.c:488
#: ../src/properties.c:505
msgid "TB"
msgstr ""
#: ../src/properties.c:560
#: ../src/properties.c:541
msgid "Properties of "
msgstr ""
#: ../src/properties.c:627
msgid "Usage: properties file...\n"
msgstr ""

View File

@ -114,7 +114,7 @@ open.o: open.c
$(CC) $(open_CFLAGS) -c open.c
properties.o: properties.c
$(CC) $(properties_CFLAGS) -c properties.c
$(CC) -D WITH_MAIN $(properties_CFLAGS) -c properties.c
view.o: view.c
$(CC) $(view_CFLAGS) -c view.c

View File

@ -35,7 +35,7 @@ properties.so: $(properties_OBJS)
devices.o: devices.c ../../include/Browser.h
$(CC) $(devices_CFLAGS) -c devices.c
properties.o: properties.c ../../include/Browser.h
properties.o: properties.c ../../include/Browser.h ../properties.c
$(CC) $(properties_CFLAGS) -c properties.c
clean:

View File

@ -19,4 +19,4 @@ sources=properties.c
install=$(LIBDIR)/Browser/plugins
[properties.c]
depends=../../include/Browser.h
depends=../../include/Browser.h,../properties.c

View File

@ -18,21 +18,17 @@
#include <System.h>
#include <libintl.h>
#include "Browser.h"
#define N_(string) (string)
#define _properties_refresh _properties_do_refresh
#include "../properties.c"
#undef _properties_refresh
/* Properties */
/* private */
/* types */
typedef struct _Properties
{
GtkWidget * view;
} Properties;
/* prototypes */
static GtkWidget * _properties_init(BrowserPlugin * plugin);
static void _properties_destroy(BrowserPlugin * plugin);
static void _properties_refresh(BrowserPlugin * plugin, char const * path);
/* public */
@ -44,7 +40,7 @@ BrowserPlugin plugin =
GTK_STOCK_PROPERTIES,
_properties_init,
_properties_destroy,
NULL,
_properties_refresh,
NULL
};
@ -55,17 +51,11 @@ BrowserPlugin plugin =
static GtkWidget * _properties_init(BrowserPlugin * plugin)
{
Properties * properties;
GtkWidget * widget;
if((properties = object_new(sizeof(*properties))) == NULL)
if((properties = _properties_new(NULL, NULL)) == NULL)
return NULL;
plugin->priv = properties;
properties->view = gtk_vbox_new(FALSE, 4);
/* FIXME really implement */
widget = gtk_label_new("Folder");
gtk_box_pack_start(GTK_BOX(properties->view), widget, FALSE, TRUE, 0);
gtk_widget_show_all(properties->view);
return properties->view;
return _properties_get_view(properties);
}
@ -74,6 +64,17 @@ static void _properties_destroy(BrowserPlugin * plugin)
{
Properties * properties = plugin->priv;
gtk_widget_destroy(properties->view);
object_delete(properties);
_properties_delete(properties);
}
/* properties_refresh */
static void _properties_refresh(BrowserPlugin * plugin, char const * path)
{
Properties * properties = plugin->priv;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, path);
#endif
_properties_set_filename(properties, path);
}

View File

@ -65,6 +65,9 @@ type=binary
sources=properties.c
install=$(BINDIR)
[properties.c]
cppflags=-D WITH_MAIN
[view]
type=binary
sources=view.c

View File

@ -33,6 +33,7 @@
#include <Desktop.h>
#include "../config.h"
#define _(string) gettext(string)
#define N_(string) (string)
/* constants */
@ -51,14 +52,20 @@
/* types */
typedef struct _Properties
{
Mime * mime;
char * filename;
uid_t uid;
gid_t gid;
/* widgets */
GtkIconTheme * theme;
GtkWidget * window;
GtkWidget * combo;
GtkWidget * view;
GtkWidget * name;
GtkWidget * type;
GtkWidget * image;
GtkWidget * owner;
GtkWidget * group;
GtkWidget * size;
GtkWidget * atime;
GtkWidget * mtime;
@ -71,194 +78,95 @@ typedef struct _Properties
static unsigned int _properties_cnt = 0; /* XXX set as static in _properties */
/* functions */
#ifdef WITH_MAIN
static int _properties(Mime * mime, int filec, char * const filev[]);
#endif
static Properties * _properties_new(char const * filename, Mime * mime);
static void _properties_delete(Properties * properties);
#ifndef WITH_MAIN
static GtkWidget * _properties_get_view(Properties * properties);
#endif
static int _properties_set_filename(Properties * properties,
char const * filename);
static int _properties_error(Properties * properties, char const * message,
int ret);
static int _properties_do(Mime * mime, GtkIconTheme * theme,
char const * filename);
static int _properties_refresh(Properties * properties);
#ifdef WITH_MAIN
static void _properties_show_window(Properties * properties);
/* callbacks */
static void _properties_on_apply(gpointer data);
static void _properties_on_close(gpointer data);
static gboolean _properties_on_closex(gpointer data);
static void _properties_on_refresh(gpointer data);
#endif
#ifdef WITH_MAIN
/* properties */
static int _properties(Mime * mime, int filec, char * const filev[])
{
int ret = 0;
GtkIconTheme * theme = NULL;
int i;
Properties * properties;
if(mime != NULL)
theme = gtk_icon_theme_get_default();
for(i = 0; i < filec; i++)
{
_properties_cnt++;
/* FIXME if relative path get the full path */
ret |= _properties_do(mime, theme, filev[i]);
if((properties = _properties_new(filev[i], mime))
== NULL)
{
ret |= 1;
continue;
}
_properties_show_window(properties);
_properties_cnt++;
}
return ret;
}
/* _properties_error */
static void _error_response(GtkWidget * widget, gint arg, gpointer data);
static int _properties_error(Properties * properties, char const * message,
int ret)
{
GtkWidget * dialog;
char const * error;
error = strerror(errno);
dialog = gtk_message_dialog_new((properties != NULL)
? GTK_WINDOW(properties->window) : NULL, 0,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
#if GTK_CHECK_VERSION(2, 6, 0)
"%s", _("Error"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
#endif
"%s: %s", message, error);
gtk_window_set_title(GTK_WINDOW(dialog), _("Error"));
if(properties != NULL)
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(
properties->window));
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
_error_response), (ret != 0)
? &_properties_cnt : NULL);
gtk_widget_show(dialog);
return ret;
}
static void _error_response(GtkWidget * widget, gint arg, gpointer data)
{
unsigned int * cnt = data;
if(cnt == NULL)
gtk_widget_destroy(widget);
else if(--(*cnt) == 0)
gtk_main_quit();
else
gtk_widget_destroy(widget);
}
/* _properties_do */
static char * _do_group(char * buf, size_t buf_cnt, gid_t gid);
static GtkWidget * _do_groups(Properties * properties);
static int _properties_do(Mime * mime, GtkIconTheme * theme,
char const * filename)
/* properties_new */
static Properties * _properties_new(char const * filename, Mime * mime)
{
Properties * properties;
struct stat st;
char * gfilename;
char const * type = NULL;
struct stat dirst;
GdkPixbuf * pixbuf = NULL;
GtkWidget * image = NULL;
char buf[256];
GtkWidget * vbox;
GtkWidget * hbox;
size_t i;
GtkWidget * bbox;
GtkWidget * table;
GtkWidget * hbox;
GtkWidget * widget;
PangoFontDescription * bold;
char * p;
size_t i;
if(lstat(filename, &st) != 0)
return -_properties_error(NULL, filename, 1);
if((properties = malloc(sizeof(*properties))) == NULL)
return -_properties_error(NULL, "malloc", 1);
properties->filename = strdup(filename);
properties->uid = st.st_uid;
properties->gid = st.st_gid;
properties->combo = NULL;
if(properties->filename == NULL)
{
/* XXX warn the user */
free(properties);
return -1;
_properties_error(NULL, "malloc", 1);
return NULL;
}
gfilename = g_filename_display_name(filename);
if(S_ISDIR(st.st_mode))
{
if(theme != NULL && (pixbuf = gtk_icon_theme_load_icon(theme,
"gnome-fs-directory", 48, 0,
NULL)) != NULL)
image = gtk_image_new_from_pixbuf(pixbuf);
if(image == NULL)
image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_DIALOG);
type = "inode/directory";
if((p = strdup(filename)) != NULL
&& lstat(dirname(p), &dirst) == 0
&& st.st_dev != dirst.st_dev)
type = "inode/mountpoint";
free(p);
}
else if(S_ISBLK(st.st_mode))
type = "inode/blockdevice";
else if(S_ISBLK(st.st_mode))
type = "inode/chardevice";
else if(S_ISFIFO(st.st_mode))
type = "inode/fifo";
else if(S_ISLNK(st.st_mode))
type = "inode/symlink";
#ifdef S_ISSOCK
else if(S_ISSOCK(st.st_mode))
type = "inode/socket";
#endif
else if(mime != NULL)
{
type = mime_type(mime, filename);
if(theme != NULL && type != NULL)
{
mime_icons(mime, type, 48, &pixbuf, -1);
if(pixbuf != NULL)
image = gtk_image_new_from_pixbuf(pixbuf);
}
}
else
type = "Unknown type";
if(image == NULL && theme != NULL && (pixbuf = gtk_icon_theme_load_icon(
theme, "gnome-fs-regular", 48, 0, NULL))
!= NULL)
image = gtk_image_new_from_pixbuf(pixbuf);
if(image == NULL)
image = gtk_image_new_from_stock(GTK_STOCK_FILE,
GTK_ICON_SIZE_DIALOG);
if(image == NULL)
image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE,
GTK_ICON_SIZE_DIALOG);
properties->window = gtk_dialog_new();
p = g_filename_display_basename(filename);
snprintf(buf, sizeof(buf), "%s%s", _("Properties of "), p);
g_free(p);
gtk_window_set_title(GTK_WINDOW(properties->window), buf);
gtk_window_set_resizable(GTK_WINDOW(properties->window), FALSE);
g_signal_connect_swapped(G_OBJECT(properties->window), "delete-event",
G_CALLBACK(_properties_on_closex), properties);
#if GTK_CHECK_VERSION(2, 14, 0)
vbox = gtk_dialog_get_content_area(GTK_DIALOG(properties->window));
#else
vbox = GTK_DIALOG(properties->window)->vbox;
#endif
properties->mime = mime;
properties->theme = gtk_icon_theme_get_default();
properties->window = NULL;
properties->group = NULL;
properties->view = gtk_vbox_new(FALSE, 4);
table = gtk_table_new(12, 2, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(table), 4);
gtk_table_set_row_spacings(GTK_TABLE(table), 4);
gtk_table_set_col_spacings(GTK_TABLE(table), 4);
gtk_table_attach_defaults(GTK_TABLE(table), image, 0, 1, 0, 2);
widget = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(widget), gfilename);
gtk_editable_set_editable(GTK_EDITABLE(widget), FALSE);
properties->image = gtk_image_new();
gtk_table_attach_defaults(GTK_TABLE(table), properties->image, 0, 1, 0,
2);
properties->name = gtk_entry_new();
gtk_editable_set_editable(GTK_EDITABLE(properties->name), FALSE);
bold = pango_font_description_new();
pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD);
gtk_widget_modify_font(widget, bold);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 0, 1);
widget = gtk_label_new(type);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 1, 2);
gtk_widget_modify_font(properties->name, bold);
gtk_table_attach_defaults(GTK_TABLE(table), properties->name, 1, 2, 0,
1);
properties->type = gtk_label_new(NULL);
gtk_table_attach_defaults(GTK_TABLE(table), properties->type, 1, 2, 1,
2);
widget = gtk_label_new(_("Size:"));
gtk_widget_modify_font(widget, bold);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 0, 1, 2, 3);
@ -274,11 +182,9 @@ static int _properties_do(Mime * mime, GtkIconTheme * theme,
widget = gtk_label_new(_("Group:")); /* group name */
gtk_widget_modify_font(widget, bold);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 0, 1, 4, 5);
if(properties == NULL)
widget = gtk_label_new(_do_group(buf, sizeof(buf), st.st_gid));
else
widget = _do_groups(properties);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 1, 2, 4, 5);
properties->group = gtk_combo_box_new_text();
gtk_table_attach_defaults(GTK_TABLE(table), properties->group, 1, 2, 4,
5);
widget = gtk_label_new(_("Accessed:")); /* last access */
gtk_widget_modify_font(widget, bold);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 0, 1, 5, 6);
@ -324,95 +230,98 @@ static int _properties_do(Mime * mime, GtkIconTheme * theme,
widget = gtk_label_new(_("Others:"));
gtk_widget_modify_font(widget, bold);
gtk_table_attach_defaults(GTK_TABLE(table), widget, 0, 1, 11, 12);
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
/* button box */
#if GTK_CHECK_VERSION(2, 14, 0)
bbox = gtk_dialog_get_action_area(GTK_DIALOG(properties->window));
#else
bbox = GTK_DIALOG(properties->window)->action_area;
#endif
if(properties != NULL)
{
widget = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
g_signal_connect_swapped(G_OBJECT(widget), "clicked",
G_CALLBACK(_properties_on_refresh), properties);
gtk_container_add(GTK_CONTAINER(bbox), widget);
widget = gtk_button_new_from_stock(GTK_STOCK_APPLY);
g_signal_connect_swapped(G_OBJECT(widget), "clicked",
G_CALLBACK(_properties_on_apply), properties);
gtk_container_add(GTK_CONTAINER(bbox), widget);
}
widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
_properties_on_close), properties);
gtk_container_add(GTK_CONTAINER(bbox), widget);
pango_font_description_free(bold);
g_free(gfilename);
if(_properties_refresh(properties) != 0)
{
if(filename != NULL)
_properties_set_filename(properties, filename);
gtk_box_pack_start(GTK_BOX(properties->view), table, FALSE, TRUE, 0);
gtk_widget_show_all(properties->view);
return properties;
}
/* properties_delete */
static void _properties_delete(Properties * properties)
{
gtk_widget_destroy(properties->view);
if(properties->window != NULL)
gtk_widget_destroy(properties->window);
free(properties->filename);
/* FIXME implement the rest */
free(properties);
return 1;
}
gtk_widget_show_all(properties->window);
return 0;
_properties_cnt--;
}
static char * _do_group(char * buf, size_t buf_cnt, gid_t gid)
{
struct group * gr;
if((gr = getgrgid(gid)) != NULL)
return gr->gr_name;
snprintf(buf, buf_cnt, "%lu", (unsigned long)gid);
return buf;
#ifndef WITH_MAIN
/* properties_get_view */
static GtkWidget * _properties_get_view(Properties * properties)
{
return properties->view;
}
#endif
/* properties_set_filename */
static int _properties_set_filename(Properties * properties,
char const * filename)
{
char * p;
if((p = strdup(filename)) == NULL)
return -_properties_error(NULL, filename, 1);
free(properties->filename);
properties->filename = p;
return _properties_refresh(properties);
}
static GtkWidget * _do_groups(Properties * properties)
{
GtkWidget * box;
GtkWidget * combo;
int i = 0;
int active;
struct passwd * pw;
struct group * gr;
char ** p;
if((gr = getgrgid(getgid())) == NULL)
{
_properties_error(properties, properties->filename, 0);
return gtk_label_new("");
}
box = gtk_hbox_new(TRUE, 0);
combo = gtk_combo_box_new_text();
properties->combo = combo;
gtk_combo_box_insert_text(GTK_COMBO_BOX(combo), i, gr->gr_name);
active = i++;
gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0);
if((pw = getpwuid(getuid())) == NULL)
{
_properties_error(properties, properties->filename, 0);
return combo;
}
setgrent();
for(gr = getgrent(); gr != NULL; gr = getgrent())
for(p = gr->gr_mem; p != NULL && *p != NULL; p++)
if(strcmp(pw->pw_name, *p) == 0)
{
if(properties->gid == gr->gr_gid)
active = i;
gtk_combo_box_insert_text(GTK_COMBO_BOX(combo),
i++, gr->gr_name);
}
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active);
return box;
/* _properties_error */
static void _error_response(GtkWidget * widget, gint arg, gpointer data);
static int _properties_error(Properties * properties, char const * message,
int ret)
{
GtkWidget * dialog;
char const * error;
error = strerror(errno);
dialog = gtk_message_dialog_new((properties != NULL)
? GTK_WINDOW(properties->window) : NULL, 0,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
#if GTK_CHECK_VERSION(2, 6, 0)
"%s", _("Error"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
#endif
"%s: %s", message, error);
gtk_window_set_title(GTK_WINDOW(dialog), _("Error"));
if(properties != NULL)
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(
properties->window));
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
_error_response), (ret != 0)
? &_properties_cnt : NULL);
gtk_widget_show(dialog);
return ret;
}
static void _error_response(GtkWidget * widget, gint arg, gpointer data)
{
unsigned int * cnt = data;
if(cnt == NULL)
gtk_widget_destroy(widget);
else if(--(*cnt) == 0)
gtk_main_quit();
else
gtk_widget_destroy(widget);
}
/* properties_refresh */
static void _refresh_name(GtkWidget * widget, char const * filename);
static void _refresh_type(Properties * properties, struct stat * st);
static void _refresh_mode(GtkWidget ** widget, mode_t mode, gboolean sensitive);
static void _refresh_owner(Properties * properties, uid_t uid);
static int _refresh_group(Properties * properties, gid_t gid);
static void _refresh_size(Properties * properties, size_t size);
static void _refresh_time(GtkWidget * widget, time_t time);
@ -423,6 +332,8 @@ static int _properties_refresh(Properties * properties)
if(lstat(properties->filename, &st) != 0)
return _properties_error(NULL, properties->filename, 0) + 1;
_refresh_name(properties->name, properties->filename);
_refresh_type(properties, &st);
properties->uid = st.st_uid;
properties->gid = st.st_gid;
writable = (access(properties->filename, W_OK) == 0) ? TRUE : FALSE;
@ -430,7 +341,7 @@ static int _properties_refresh(Properties * properties)
_refresh_mode(&properties->mode[3], (st.st_mode & 0070) >> 3, writable);
_refresh_mode(&properties->mode[0], st.st_mode & 0007, writable);
_refresh_owner(properties, st.st_uid);
/* FIXME also refresh the group */
_refresh_group(properties, st.st_gid);
_refresh_size(properties, st.st_size);
_refresh_time(properties->atime, st.st_atime);
_refresh_time(properties->mtime, st.st_mtime);
@ -438,6 +349,79 @@ static int _properties_refresh(Properties * properties)
return 0;
}
static void _refresh_name(GtkWidget * widget, char const * filename)
{
gchar * gfilename;
gfilename = g_filename_display_name(filename);
gtk_entry_set_text(GTK_ENTRY(widget), gfilename);
g_free(gfilename);
}
static void _refresh_type(Properties * properties, struct stat * st)
{
char const * type = NULL;
GdkPixbuf * pixbuf = NULL;
GtkWidget * image = NULL;
char * p;
struct stat dirst;
if(S_ISDIR(st->st_mode))
{
if((pixbuf = gtk_icon_theme_load_icon(properties->theme,
"gnome-fs-directory", 48, 0,
NULL)) != NULL)
image = gtk_image_new_from_pixbuf(pixbuf);
if(image == NULL)
image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_DIALOG);
type = "inode/directory";
if((p = strdup(properties->filename)) != NULL
&& lstat(dirname(p), &dirst) == 0
&& st->st_dev != dirst.st_dev)
type = "inode/mountpoint";
free(p);
}
else if(S_ISBLK(st->st_mode))
type = "inode/blockdevice";
else if(S_ISBLK(st->st_mode))
type = "inode/chardevice";
else if(S_ISFIFO(st->st_mode))
type = "inode/fifo";
else if(S_ISLNK(st->st_mode))
type = "inode/symlink";
#ifdef S_ISSOCK
else if(S_ISSOCK(st->st_mode))
type = "inode/socket";
#endif
else if(properties->mime != NULL)
{
type = mime_type(properties->mime, properties->filename);
if(type != NULL)
{
mime_icons(properties->mime, type, 48, &pixbuf, -1);
if(pixbuf != NULL)
image = gtk_image_new_from_pixbuf(pixbuf);
}
}
else
type = _("Unknown type");
gtk_label_set_text(GTK_LABEL(properties->type), type);
if(image == NULL && (pixbuf = gtk_icon_theme_load_icon(
properties->theme, "gnome-fs-regular",
48, 0, NULL)) != NULL)
image = gtk_image_new_from_pixbuf(pixbuf);
if(image == NULL)
image = gtk_image_new_from_stock(GTK_STOCK_FILE,
GTK_ICON_SIZE_DIALOG);
if(image == NULL)
image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE,
GTK_ICON_SIZE_DIALOG);
gtk_image_set_from_pixbuf(GTK_IMAGE(properties->image),
gtk_image_get_pixbuf(GTK_IMAGE(image)));
gtk_widget_destroy(image);
}
static void _refresh_mode(GtkWidget ** widget, mode_t mode, gboolean sensitive)
{
gtk_button_set_label(GTK_BUTTON(widget[2]), _("read")); /* read */
@ -467,6 +451,39 @@ static void _refresh_owner(Properties * properties, uid_t uid)
gtk_label_set_text(GTK_LABEL(properties->owner), p);
}
static int _refresh_group(Properties * properties, gid_t gid)
{
GtkWidget * combo;
GtkListStore * store;
int i = 0;
int active;
struct passwd * pw;
struct group * gr;
char ** p;
combo = properties->group;
store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
gtk_list_store_clear(store);
if((gr = getgrgid(getgid())) == NULL)
return -_properties_error(properties, properties->filename, 1);
gtk_combo_box_insert_text(GTK_COMBO_BOX(combo), i, gr->gr_name);
active = i++;
if((pw = getpwuid(getuid())) == NULL)
return -_properties_error(properties, properties->filename, 1);
setgrent();
for(gr = getgrent(); gr != NULL; gr = getgrent())
for(p = gr->gr_mem; p != NULL && *p != NULL; p++)
if(strcmp(pw->pw_name, *p) == 0)
{
if(gid == gr->gr_gid)
active = i;
gtk_combo_box_insert_text(GTK_COMBO_BOX(combo),
i++, gr->gr_name);
}
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active);
return 0;
}
static void _refresh_size(Properties * properties, size_t size)
{
char buf[256];
@ -507,6 +524,55 @@ static void _refresh_time(GtkWidget * widget, time_t t)
}
#ifdef WITH_MAIN
/* properties_show_window */
static void _properties_show_window(Properties * properties)
{
GtkWidget * vbox;
GtkWidget * bbox;
GtkWidget * widget;
gchar * p;
char buf[256];
if(properties->window != NULL)
return;
properties->window = gtk_dialog_new();
p = g_filename_display_basename(properties->filename);
snprintf(buf, sizeof(buf), "%s%s", _("Properties of "), p);
g_free(p);
gtk_window_set_title(GTK_WINDOW(properties->window), buf);
gtk_window_set_resizable(GTK_WINDOW(properties->window), FALSE);
g_signal_connect_swapped(G_OBJECT(properties->window), "delete-event",
G_CALLBACK(_properties_on_closex), properties);
#if GTK_CHECK_VERSION(2, 14, 0)
vbox = gtk_dialog_get_content_area(GTK_DIALOG(properties->window));
#else
vbox = GTK_DIALOG(properties->window)->vbox;
#endif
gtk_box_pack_start(GTK_BOX(vbox), properties->view, FALSE, TRUE, 0);
/* button box */
#if GTK_CHECK_VERSION(2, 14, 0)
bbox = gtk_dialog_get_action_area(GTK_DIALOG(properties->window));
#else
bbox = GTK_DIALOG(properties->window)->action_area;
#endif
widget = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
g_signal_connect_swapped(G_OBJECT(widget), "clicked",
G_CALLBACK(_properties_on_refresh), properties);
gtk_container_add(GTK_CONTAINER(bbox), widget);
widget = gtk_button_new_from_stock(GTK_STOCK_APPLY);
g_signal_connect_swapped(G_OBJECT(widget), "clicked",
G_CALLBACK(_properties_on_apply), properties);
gtk_container_add(GTK_CONTAINER(bbox), widget);
widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
_properties_on_close), properties);
gtk_container_add(GTK_CONTAINER(bbox), widget);
gtk_widget_show_all(bbox);
gtk_widget_show(properties->window);
}
/* callbacks */
static void _properties_on_apply(gpointer data)
{
@ -517,7 +583,7 @@ static void _properties_on_apply(gpointer data)
size_t i;
mode_t mode = 0;
p = gtk_combo_box_get_active_text(GTK_COMBO_BOX(properties->combo));
p = gtk_combo_box_get_active_text(GTK_COMBO_BOX(properties->group));
if((gr = getgrnam(p)) == NULL)
_properties_error(properties, p, 0);
else
@ -534,10 +600,9 @@ static void _properties_on_close(gpointer data)
{
Properties * properties = data;
if(--_properties_cnt == 0)
_properties_delete(properties);
if(_properties_cnt == 0)
gtk_main_quit();
else
gtk_widget_destroy(properties->window);
}
static gboolean _properties_on_closex(gpointer data)
@ -552,8 +617,10 @@ static void _properties_on_refresh(gpointer data)
_properties_refresh(properties);
}
#endif
#ifdef WITH_MAIN
/* usage */
static int _usage(void)
{
@ -588,3 +655,4 @@ int main(int argc, char * argv[])
mime_delete(mime);
return (ret == 0) ? 0 : 2;
}
#endif