Commit 586355bd authored by Allison Karlitskaya's avatar Allison Karlitskaya Committed by Paolo Borelli

Begin rewrite in Vala

The current baobab code is in a bad way, so after some discussion on
IRC, we've decided that a rewrite is in order.

 - the core application logic will be switched to Vala

 - more effective use will be made of GtkBuilder

 - the charts (ringchart, treemap) and progress cell renderer are
   well-written, so we will keep the C versions of them around

 - the port will make use of GtkApplication, including GMenu

This commit represents the very start of a rather large
work-in-progress.
parent 03a40a60
......@@ -8,7 +8,7 @@ PKG_NAME="baobab"
(test -f $srcdir/configure.ac \
&& test -f $srcdir/README \
&& test -f $srcdir/src/baobab.c) || {
&& test -f $srcdir/src/main.vala) || {
echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
echo " top-level $PKG_NAME directory"
exit 1
......
......@@ -7,7 +7,7 @@ AC_INIT([baobab],
[baobab])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_SRCDIR(src/baobab.c)
AC_CONFIG_SRCDIR(src/main.vala)
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_TARGET
......@@ -29,6 +29,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The name of the gettext d
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AM_PROG_VALAC
PKG_PROG_PKG_CONFIG([0.22])
## don't rerun to this point if we abort
......@@ -39,11 +40,8 @@ GLIB_GSETTINGS
# Mallard help
YELP_HELP_INIT
PKG_CHECK_MODULES(BAOBAB, [
glib-2.0 >= 2.30.0
gtk+-3.0 >= 3.3.18
libgtop-2.0
])
PKG_CHECK_MODULES(gtk, gtk+-3.0 >= 3.3.18)
PKG_CHECK_MODULES(gio, gio-2.0 >= 2.30.0)
AC_CONFIG_FILES([
Makefile
......@@ -59,8 +57,9 @@ AC_OUTPUT
echo "
Baobab $VERSION
prefix: ${prefix}
compiler: ${CC}
prefix: ${prefix}
Vala compiler: ${VALAC}
C compiler: ${CC}
Now type 'make' to build $PACKAGE
"
This diff is collapsed.
......@@ -2,6 +2,7 @@ NULL =
INCLUDES = \
-DPREFIX=\""$(prefix)"\" \
-DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DLIBDIR=\""$(libdir)"\" \
-DDATADIR=\""$(datadir)"\" \
......@@ -12,38 +13,39 @@ INCLUDES = \
bin_PROGRAMS = baobab
baobab_VALAFLAGS = --pkg gtk+-3.0
baobab_SOURCES = \
baobab.c \
baobab.h \
baobab-cell-renderer-progress.c \
baobab-cell-renderer-progress.h \
baobab-ringschart.c \
baobab-ringschart.h \
baobab-scan.c \
baobab-scan.h \
baobab-treeview.c \
baobab-treeview.h \
baobab-utils.c \
baobab-utils.h \
callbacks.c \
callbacks.h \
baobab-prefs.c \
baobab-prefs.h \
baobab-remote-connect-dialog.c \
baobab-remote-connect-dialog.h \
baobab-chart.c \
baobab-chart.h \
baobab-treemap.c \
baobab-treemap.h
baobab.vapi \
config.vapi \
baobab-chart.c \
baobab-treemap.c \
baobab-ringschart.c \
baobab-scanner.vala \
baobab-cell-renderer-progress.c \
baobab-cellrenderers.vala \
baobab-application.vala \
baobab-window.vala \
main.vala
baobab_CFLAGS = \
$(BAOBAB_CFLAGS) \
AM_CFLAGS = \
$(gtk_CFLAGS) \
-Wall \
-Wno-unused-but-set-variable \
-Wno-unused-variable \
$(NULL)
baobab_LDFLAGS = -export-dynamic
baobab_LDADD = \
baobab_LDADD = \
-lm \
$(BAOBAB_LIBS) \
$(gtk_LIBS) \
$(NULL)
MAINTAINERCLEANFILES = \
baobab-application.c \
baobab-scanner.c \
baobab-cellrenderers.c \
baobab-window.c \
baobab_vala.stamp \
main.c
-include $(top_srcdir)/git.mk
/* Baobab - disk usage analyzer
*
* Copyright (C) 2012 Ryan Lortie <desrt@desrt.ca>
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace Baobab {
public class Application : Gtk.Application {
Settings desktop_settings;
Settings prefs_settings;
Settings ui_settings;
File[] excluded_locations;
static Application baobab;
protected override void activate () {
new Window (this);
}
protected override void open (File[] files, string hint) {
foreach (var file in files) {
var window = new Window (this);
window.scan_directory (file);
}
}
void excluded_uris_changed (Settings settings, string key) {
var uris = settings.get_strv (key);
excluded_locations = new File[0];
var root = File.new_for_path ("/");
foreach (var uri in uris) {
var file = File.new_for_uri (uri);
if (!file.equal (root)) {
excluded_locations += file;
}
}
}
protected override void startup () {
base.startup ();
baobab = this;
ui_settings = new Settings ("org.gnome.baobab.ui");
prefs_settings = new Settings ("org.gnome.baobab.preferences");
desktop_settings = new Settings ("org.gnome.desktop.interface");
excluded_uris_changed (prefs_settings, "excluded-uris");
prefs_settings.changed["excluded-uris"] += excluded_uris_changed;
}
protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)] ref unowned string[] arguments, out int exit_status) {
if (arguments[1] == "-v") {
print ("%s %s\n", Environment.get_application_name (), Config.VERSION);
exit_status = 0;
return true;
}
return base.local_command_line (ref arguments, out exit_status);
}
public Application () {
Object (application_id: "org.gnome.baobab", flags: ApplicationFlags.HANDLES_OPEN);
}
public static bool is_excluded_location (File file) {
var app = baobab;
foreach (var location in app.excluded_locations) {
if (file.equal (location)) {
return true;
}
}
return false;
}
public static Settings get_desktop_settings () {
var app = baobab;
return app.desktop_settings;
}
public static Settings get_prefs_settings () {
var app = baobab;
return app.prefs_settings;
}
public static Settings get_ui_settings () {
var app = baobab;
return app.ui_settings;
}
}
}
/*
* baobab-treeview.h
* This file is part of baobab
/* Baobab - disk usage analyzer
*
* Copyright (C) 2005-2006 Fabio Marzocca <thesaltydog@gmail.com>
* Copyright (C) 2012 Ryan Lortie <desrt@desrt.ca>
*
* 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 2 of the License, or
* (at your option) any later version.
* 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 2
* 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
......@@ -16,32 +14,43 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __BAOBAB_TV_H__
#define __BAOBAB_TV_H__
namespace Baobab {
public class CellRendererPercent : Gtk.CellRendererText {
public double percent {
set {
text = "%.1f %%".printf (value);
}
}
}
#include <gtk/gtk.h>
public class CellRendererSize : Gtk.CellRendererText {
public new uint64 size {
set {
if (!show_allocated_size) {
text = format_size (value);
}
}
}
/* tree model columns (_H_ are hidden) */
enum
{
COL_DIR_NAME,
COL_H_PARSENAME,
COL_H_PERC,
COL_DIR_SIZE,
COL_H_SIZE,
COL_H_ALLOCSIZE,
COL_ELEMENTS,
COL_H_ELEMENTS,
COL_HARDLINK,
COL_H_HARDLINK,
NUM_TREE_COLUMNS
};
public uint64 alloc_size {
set {
if (show_allocated_size) {
text = format_size (value);
}
}
}
GtkWidget *create_directory_treeview (void);
void baobab_treeview_show_allocated_size (GtkWidget *tv, gboolean show_allocated);
public bool show_allocated_size { private get; set; }
}
#endif /* __BAOBAB_TV_H__ */
public class CellRendererItems : Gtk.CellRendererText {
public int items {
set {
text = ngettext ("%d item", "%d items", value).printf (value);
}
}
}
}
/*
* baobab-prefs.c
* This file is part of baobab
*
* Copyright (C) 2005-2006 Fabio Marzocca <thesaltydog@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <sys/stat.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <glibtop/mountlist.h>
#include <glibtop/fsusage.h>
#include "baobab.h"
#include "baobab-utils.h"
#include "baobab-prefs.h"
#define BAOBAB_PREFERENCES_UI_FILE PKGDATADIR "/baobab-preferences-dialog.ui"
enum
{
COL_CHECK,
COL_CHECK_SENS,
COL_DEVICE,
COL_MOUNT_D,
COL_MOUNT,
COL_TYPE,
COL_FS_SIZE,
COL_FS_AVAIL,
TOT_COLUMNS
};
static gboolean
add_excluded_item (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
GPtrArray *uris)
{
gchar *mount;
gboolean check;
gtk_tree_model_get (model,
iter,
COL_MOUNT, &mount,
COL_CHECK, &check,
-1);
if (!check) {
g_ptr_array_add (uris, mount);
}
else {
g_free (mount);
}
return FALSE;
}
static gchar **
get_excluded_locations (GtkTreeModel *model)
{
GPtrArray *uris;
uris = g_ptr_array_new ();
gtk_tree_model_foreach (model,
(GtkTreeModelForeachFunc) add_excluded_item,
uris);
g_ptr_array_add (uris, NULL);
return (gchar **) g_ptr_array_free (uris, FALSE);
}
static void
save_excluded_uris (GtkTreeModel *model)
{
gchar **uris;
uris = get_excluded_locations (model);
g_settings_set_strv (baobab.prefs_settings,
BAOBAB_SETTINGS_EXCLUDED_URIS,
(const gchar * const *) uris);
g_strfreev (uris);
}
static void
filechooser_response_cb (GtkDialog *dialog,
gint response_id,
GtkTreeModel *model)
{
switch (response_id) {
case GTK_RESPONSE_HELP:
baobab_help_display (GTK_WINDOW (baobab.window), "pref");
break;
case GTK_RESPONSE_DELETE_EVENT:
case GTK_RESPONSE_CLOSE:
save_excluded_uris (model);
default:
gtk_widget_destroy (GTK_WIDGET (dialog));
break;
}
}
static void
check_toggled (GtkCellRendererToggle *cell,
gchar *path_str,
GtkTreeModel *model)
{
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
gboolean toggle;
gchar *mountpoint;
/* get toggled iter */
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model,
&iter,
COL_CHECK, &toggle,
COL_MOUNT_D, &mountpoint,
-1);
/* check if root dir */
if (strcmp ("/", mountpoint) == 0)
goto clean_up;
/* set new value */
gtk_list_store_set (GTK_LIST_STORE (model),
&iter,
COL_CHECK, !toggle,
-1);
clean_up:
g_free (mountpoint);
gtk_tree_path_free (path);
}
static void
create_tree_props (GtkBuilder *builder, GtkTreeModel *model)
{
GtkCellRenderer *cell;
GtkTreeViewColumn *col;
GtkWidget *tvw;
tvw = GTK_WIDGET (gtk_builder_get_object (builder , "tree_view_props"));
/* checkbox column */
cell = gtk_cell_renderer_toggle_new ();
g_signal_connect (cell, "toggled",
G_CALLBACK (check_toggled), model);
col = gtk_tree_view_column_new_with_attributes (_("Scan"), cell,
"active", COL_CHECK,
"sensitive", COL_CHECK_SENS,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tvw), col);
/* First text column */
cell = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("Device"), cell,
"markup", COL_DEVICE,
"text", COL_DEVICE,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tvw), col);
/* second text column */
cell = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("Mount Point"),
cell, "markup",
COL_MOUNT_D, "text",
COL_MOUNT_D, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tvw), col);
/* third text column */
cell = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("File System Type"),
cell, "markup",
COL_TYPE, "text",
COL_TYPE, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tvw), col);
/* fourth text column */
cell = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("Total Size"),
cell, "markup",
COL_FS_SIZE, "text",
COL_FS_SIZE, NULL);
g_object_set (G_OBJECT (cell), "xalign", (gfloat) 1.0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tvw), col);
/* fifth text column */
cell = gtk_cell_renderer_text_new ();
col = gtk_tree_view_column_new_with_attributes (_("Available"),
cell, "markup",
COL_FS_AVAIL, "text",
COL_FS_AVAIL, NULL);
g_object_set (G_OBJECT (cell), "xalign", (gfloat) 1.0, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tvw), col);
gtk_tree_view_set_model (GTK_TREE_VIEW (tvw), model);
g_object_unref (model);
}
static void
fill_props_model (GtkListStore *store)
{
GtkTreeIter iter;
guint lo;
glibtop_mountlist mountlist;
glibtop_mountentry *mountentry, *mountentry_tofree;
guint64 fstotal, fsavail;
mountentry_tofree = glibtop_get_mountlist (&mountlist, 0);
for (lo = 0, mountentry = mountentry_tofree;
lo < mountlist.number;
lo++, mountentry++) {
glibtop_fsusage fsusage;
gchar * total, *avail;
GFile *file;
gchar *uri;
gboolean excluded;
gboolean sensitive;
struct stat buf;
if (g_stat (mountentry->devname,&buf) == -1)
continue;
glibtop_get_fsusage (&fsusage, mountentry->mountdir);
fstotal = fsusage.blocks * fsusage.block_size;
fsavail = fsusage.bfree * fsusage.block_size;
total = g_format_size (fstotal);
avail = g_format_size (fsavail);
file = g_file_new_for_path (mountentry->mountdir);
uri = g_file_get_uri (file);
excluded = baobab_is_excluded_location (file);
sensitive = (strcmp ("/", mountentry->mountdir) == 0) ? FALSE : TRUE;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_CHECK, !excluded,
COL_CHECK_SENS, sensitive,
COL_DEVICE, mountentry->devname,
COL_MOUNT_D, mountentry->mountdir,
COL_MOUNT, uri,
COL_TYPE, mountentry->type,
COL_FS_SIZE, total,
COL_FS_AVAIL, avail,
-1);
g_free(total);
g_free(avail);
g_free(uri);
g_object_unref(file);
}
g_free (mountentry_tofree);
}
void
baobab_prefs_dialog (void)
{
GtkBuilder *builder;
GtkWidget *dlg;
GtkWidget *check_enablehome;
GtkListStore *model;
GError *error = NULL;
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder,
BAOBAB_PREFERENCES_UI_FILE,
&error);
if (error) {
g_critical ("Can't load user interface file for the scan properties dialog: %s",
error->message);
g_object_unref (builder);
g_error_free (error);
return;
}
dlg = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_scan_props"));
gtk_window_set_transient_for (GTK_WINDOW (dlg),
GTK_WINDOW (baobab.window));
model = gtk_list_store_new (TOT_COLUMNS,
G_TYPE_BOOLEAN, /* checkbox */
G_TYPE_BOOLEAN, /* checkbox sensitivity */
G_TYPE_STRING, /* device */
G_TYPE_STRING, /*mount point display */
G_TYPE_STRING, /* mount point uri */
G_TYPE_STRING, /* fs type */
G_TYPE_STRING, /* fs size */
G_TYPE_STRING /* fs avail */
);
create_tree_props (builder, GTK_TREE_MODEL (model));
fill_props_model (model);
check_enablehome = GTK_WIDGET (gtk_builder_get_object (builder, "check_enable_home"));
g_settings_bind (baobab.prefs_settings,
BAOBAB_SETTINGS_MONITOR_HOME,
check_enablehome, "active",
G_SETTINGS_BIND_DEFAULT);
g_signal_connect (dlg, "response",
G_CALLBACK (filechooser_response_cb), model);
gtk_widget_show_all (dlg);
}
/* ex:set ts=8 noet: */
/*
* baobab-prefs.h
* This file is part of baobab
*
* Copyright (C) 2005-2006 Fabio Marzocca <thesaltydog@gmail.com>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef __BAOBAB_PROPS_H__
#define __BAOBAB_PROPS_H__
void baobab_prefs_dialog (void);
#endif /* __BAOBAB_PROPS_H__ */
This diff is collapsed.
/* Baobab - (C) 2005 Fabio Marzocca
baobab-remote-connect-dialog.h
Modified module from BaobabRemoteConnectDialog.h
Released under same licence
*/
/*
* Nautilus
*
* Copyright (C) 2003 Red Hat, Inc.