Bug fixed.

This commit is contained in:
Toshio Sekiya 2021-04-19 23:37:36 +09:00
parent 5ee29f15f9
commit 74b2be2aef
7 changed files with 294 additions and 5 deletions

2
.gitignore vendored
View file

@ -27,7 +27,7 @@ src/le
src/list4/_build
src/list5/_build
src/expression/_build
src/column
src/column/_build
html/*
latex/*

View file

@ -35,13 +35,13 @@ task md: ["Readme.md", "src/turtle/turtle_doc.md"]
file "Readme.md" => mdfilenames do
buf = [ "# Gtk4 Tutorial for beginners\n", "\n" ]
src2md "src/abstract.src.md", "gfm/abstract.md"
File.open("gfm/abstract.md") do |file|
src2md "src/abstract.src.md", "abstract.md"
File.open("abstract.md") do |file|
file.readlines.each do |line|
buf << line
end
end
File.delete("gfm/abstract.md")
File.delete("abstract.md")
buf << "\n"
buf << "## Table of contents\n\n"
buf << "\n"

View file

@ -21,7 +21,7 @@ The latest version of the tutorial is located at [Gtk4-tutorial github repositor
You can read it without download.
If you want to get a html or pdf version, you can make them with `rake`, which is a ruby version of make.
There is a [documentation](../doc/Readme_for_developers.md) how to make them.
There is a [documentation](doc/Readme_for_developers.md) how to make them.
If you have a question, feel free to post an issue.
Any question is helpful to make this tutorial get better.

115
src/column/column.c Normal file
View file

@ -0,0 +1,115 @@
#include <gtk/gtk.h>
/* functions (closures) for GtkBuilderListItemFactory */
GIcon *
get_icon_factory (GtkListItem *item, GFileInfo *info) {
GIcon *icon;
if (! G_IS_FILE_INFO (info))
return NULL;
else {
icon = g_file_info_get_icon (info);
g_object_ref (icon);
return icon;
}
}
char *
get_file_name_factory (GtkListItem *item, GFileInfo *info) {
if (! G_IS_FILE_INFO (info))
return NULL;
else
return g_strdup (g_file_info_get_name (info));
}
char *
get_file_size_factory (GtkListItem *item, GFileInfo *info) {
/* goffset is gint64 */
goffset size;
if (! G_IS_FILE_INFO (info))
return NULL;
else {
size = g_file_info_get_size (info);
return g_strdup_printf ("%ld", (long int) size);
}
}
char *
get_file_time_modified_factory (GtkListItem *item, GFileInfo *info) {
GDateTime *dt;
if (! G_IS_FILE_INFO (info))
return NULL;
else {
dt = g_file_info_get_modification_date_time (info);
return g_date_time_format (dt, "%F");
}
}
/* Functions (closures) for GtkSorter */
char *
get_file_name (GFileInfo *info) {
g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
return g_strdup(g_file_info_get_name (info));
}
goffset
get_file_size (GFileInfo *info) {
g_return_val_if_fail (G_IS_FILE_INFO (info), -1);
return g_file_info_get_size (info);
}
gint64
get_file_unixtime_modified (GFileInfo *info) {
g_return_val_if_fail (G_IS_FILE_INFO (info), -1);
GDateTime *dt;
dt = g_file_info_get_modification_date_time (info);
return g_date_time_to_unix (dt);
}
/* ----- activate, open, startup handlers ----- */
static void
app_activate (GApplication *application) {
GtkApplication *app = GTK_APPLICATION (application);
GFile *file;
GtkBuilder *build = gtk_builder_new_from_resource ("/com/github/ToshioCP/column/column.ui");
GtkWidget *win = GTK_WIDGET (gtk_builder_get_object (build, "win"));
GtkDirectoryList *directorylist = GTK_DIRECTORY_LIST (gtk_builder_get_object (build, "directorylist"));
g_object_unref (build);
gtk_window_set_application (GTK_WINDOW (win), app);
file = g_file_new_for_path (".");
gtk_directory_list_set_file (directorylist, file);
g_object_unref (file);
gtk_widget_show (win);
}
static void
app_startup (GApplication *application) {
}
#define APPLICATION_ID "com.github.ToshioCP.columnview"
int
main (int argc, char **argv) {
GtkApplication *app;
int stat;
app = gtk_application_new (APPLICATION_ID, G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
/* g_signal_connect (app, "open", G_CALLBACK (app_open), NULL);*/
stat =g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return stat;
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/github/ToshioCP/column">
<file>column.ui</file>
</gresource>
</gresources>

157
src/column/column.ui Normal file
View file

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkApplicationWindow" id="win">
<property name="title">file list</property>
<property name="default-width">800</property>
<property name="default-height">600</property>
<child>
<object class="GtkScrolledWindow" id="scr">
<property name="hexpand">TRUE</property>
<property name="vexpand">TRUE</property>
<child>
<object class="GtkColumnView" id="columnview">
<property name="model">
<object class="GtkSingleSelection" id="singleselection">
<property name="model">
<object class="GtkSortListModel" id="sortlist">
<property name="model">
<object class="GtkDirectoryList" id="directorylist">
<property name="attributes">standard::name,standard::icon,standard::size,time::modified</property>
</object>
</property>
<binding name="sorter">
<lookup name="sorter">columnview</lookup>
</binding>
</object>
</property>
</object>
</property>
<child>
<object class="GtkColumnViewColumn" id="column1">
<property name="title">Name</property>
<property name="expand">TRUE</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkBox">
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<property name="spacing">20</property>
<child>
<object class="GtkImage">
<binding name="gicon">
<closure type="GIcon" function="get_icon_factory">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="hexpand">TRUE</property>
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="get_file_name_factory">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</child>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="sorter">
<object class="GtkStringSorter" id="sorter_name">
<property name="expression">
<closure type="gchararray" function="get_file_name">
</closure>
</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="column2">
<property name="title">Size</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="hexpand">TRUE</property>
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="get_file_size_factory">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="sorter">
<object class="GtkNumericSorter" id="sorter_size">
<property name="expression">
<closure type="gint64" function="get_file_size">
</closure>
</property>
<property name="sort-order">GTK_SORT_ASCENDING</property>
</object>
</property>
</object>
</child>
<child>
<object class="GtkColumnViewColumn" id="column3">
<property name="title">Date modified</property>
<property name="factory">
<object class="GtkBuilderListItemFactory">
<property name="bytes"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<property name="hexpand">TRUE</property>
<property name="xalign">0</property>
<binding name="label">
<closure type="gchararray" function="get_file_time_modified_factory">
<lookup name="item">GtkListItem</lookup>
</closure>
</binding>
</object>
</property>
</template>
</interface>
]]></property>
</object>
</property>
<property name="sorter">
<object class="GtkNumericSorter" id="sorter_datetime_modified">
<property name="expression">
<closure type="gint64" function="get_file_unixtime_modified">
</closure>
</property>
<property name="sort-order">GTK_SORT_ASCENDING</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

11
src/column/meson.build Normal file
View file

@ -0,0 +1,11 @@
project('list5', 'c')
gtkdep = dependency('gtk4')
gnome=import('gnome')
resources = gnome.compile_resources('resources','column.gresource.xml')
sourcefiles=files('column.c')
executable('column', sourcefiles, resources, dependencies: gtkdep, export_dynamic: true, install: false)