mirror of
https://github.com/ToshioCP/Gtk4-tutorial.git
synced 2025-01-12 20:03:28 +01:00
562 lines
54 KiB
HTML
562 lines
54 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="generator" content="pandoc" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||
<title>GTK 4 tutorial</title>
|
||
<style>
|
||
code{white-space: pre-wrap;}
|
||
span.smallcaps{font-variant: small-caps;}
|
||
span.underline{text-decoration: underline;}
|
||
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
||
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
||
ul.task-list{list-style: none;}
|
||
pre{overflow: visible;}
|
||
pre > code.sourceCode { white-space: pre; position: relative; }
|
||
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
|
||
pre > code.sourceCode > span:empty { height: 1.2em; }
|
||
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
||
div.sourceCode { margin: 1em 0; }
|
||
pre.sourceCode { margin: 0; }
|
||
@media screen {
|
||
div.sourceCode { overflow: auto; }
|
||
}
|
||
@media print {
|
||
pre > code.sourceCode { white-space: pre-wrap; }
|
||
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
||
}
|
||
pre.numberSource code
|
||
{ counter-reset: source-line 0; }
|
||
pre.numberSource code > span
|
||
{ position: relative; left: -4em; counter-increment: source-line; }
|
||
pre.numberSource code > span > a:first-child::after
|
||
{ content: counter(source-line);
|
||
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
||
border: none; display: inline-block;
|
||
-webkit-touch-callout: none; -webkit-user-select: none;
|
||
-khtml-user-select: none; -moz-user-select: none;
|
||
-ms-user-select: none; user-select: none;
|
||
padding: 0 4px; width: 4em;
|
||
color: #aaaaaa;
|
||
}
|
||
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
|
||
div.sourceCode
|
||
{ }
|
||
@media screen {
|
||
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
||
}
|
||
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||
code span.at { color: #7d9029; } /* Attribute */
|
||
code span.bn { color: #40a070; } /* BaseN */
|
||
code span.bu { } /* BuiltIn */
|
||
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||
code span.ch { color: #4070a0; } /* Char */
|
||
code span.cn { color: #880000; } /* Constant */
|
||
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||
code span.dt { color: #902000; } /* DataType */
|
||
code span.dv { color: #40a070; } /* DecVal */
|
||
code span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||
code span.ex { } /* Extension */
|
||
code span.fl { color: #40a070; } /* Float */
|
||
code span.fu { color: #06287e; } /* Function */
|
||
code span.im { } /* Import */
|
||
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||
code span.op { color: #666666; } /* Operator */
|
||
code span.ot { color: #007020; } /* Other */
|
||
code span.pp { color: #bc7a00; } /* Preprocessor */
|
||
code span.sc { color: #4070a0; } /* SpecialChar */
|
||
code span.ss { color: #bb6688; } /* SpecialString */
|
||
code span.st { color: #4070a0; } /* String */
|
||
code span.va { color: #19177c; } /* Variable */
|
||
code span.vs { color: #4070a0; } /* VerbatimString */
|
||
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||
div.sourceCode { margin: 10px; padding: 16px 10px 8px 10px; border: 2px solid silver; background-color: ghostwhite; overflow-x:scroll}
|
||
pre:not(.sourceCode) { margin: 10px; padding: 16px 10px 8px 10px; border: 2px solid silver; background-color: ghostwhite; overflow-x:scroll}
|
||
table {margin-left: auto; margin-right: auto; border-collapse: collapse; border: 1px solid;}
|
||
th {padding: 2px 6px; border: 1px solid; background-color: ghostwhite;}
|
||
td {padding: 2px 6px; border: 1px solid;}
|
||
img {display: block; margin-left: auto; margin-right: auto;}
|
||
figcaption {text-align: center;}
|
||
</style>
|
||
</head>
|
||
<body style="padding-top: 70px;">
|
||
<div class="container">
|
||
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
|
||
<div class="container-fluid">
|
||
<span class="navbar-brand">Gtk4 tutorial</span>
|
||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||
<span class="navbar-toggler-icon"></span>
|
||
</button>
|
||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="index.html">Home</a>
|
||
</li>
|
||
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="sec31.html">Prev: section31</a>
|
||
</li>
|
||
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="sec33.html">Next: section33</a>
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
<h1 id="gtkcolumnview">GtkColumnView</h1>
|
||
<h2 id="gtkcolumnview-1">GtkColumnView</h2>
|
||
<p>GtkColumnView is like GtkListView, but it has multiple columns. Each
|
||
column is GtkColumnViewColumn.</p>
|
||
<figure>
|
||
<img src="image/column_view.png" alt="Column View" />
|
||
<figcaption aria-hidden="true">Column View</figcaption>
|
||
</figure>
|
||
<ul>
|
||
<li>GtkColumnView has “model” property. The property points a
|
||
GtkSelectionModel object.</li>
|
||
<li>Each GtkColumnViewColumn has “factory” property. The property points
|
||
a GtkListItemFactory (GtkSignalListItemFactory or
|
||
GtkBuilderListItemFactory).</li>
|
||
<li>The factory connects GtkListItem and items of GtkSelectionModel. And
|
||
the factory builds the descendant widgets of GtkColumnView to display
|
||
the item on the display. This process is the same as the one in
|
||
GtkListView.</li>
|
||
</ul>
|
||
<p>The following diagram shows how it works.</p>
|
||
<figure>
|
||
<img src="image/column.png" alt="ColumnView" />
|
||
<figcaption aria-hidden="true">ColumnView</figcaption>
|
||
</figure>
|
||
<p>The example in this section is a window that displays information of
|
||
files in a current directory. The information is the name, size and last
|
||
modified datetime of files. So, there are three columns.</p>
|
||
<p>In addition, the example uses GtkSortListModel and GtkSorter to sort
|
||
the information.</p>
|
||
<h2 id="column.ui">column.ui</h2>
|
||
<p>Ui file specifies widgets and list item templates.</p>
|
||
<div class="sourceCode" id="cb1"><pre
|
||
class="sourceCode numberSource xml numberLines"><code class="sourceCode xml"><span id="cb1-1"><a href="#cb1-1"></a><span class="fu"><?xml</span><span class="ot"> version=</span><span class="st">"1.0"</span><span class="ot"> encoding=</span><span class="st">"UTF-8"</span><span class="fu">?></span></span>
|
||
<span id="cb1-2"><a href="#cb1-2"></a><<span class="kw">interface</span>></span>
|
||
<span id="cb1-3"><a href="#cb1-3"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkApplicationWindow"</span><span class="ot"> id=</span><span class="st">"win"</span>></span>
|
||
<span id="cb1-4"><a href="#cb1-4"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"title"</span>>file list</<span class="kw">property</span>></span>
|
||
<span id="cb1-5"><a href="#cb1-5"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"default-width"</span>>800</<span class="kw">property</span>></span>
|
||
<span id="cb1-6"><a href="#cb1-6"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"default-height"</span>>600</<span class="kw">property</span>></span>
|
||
<span id="cb1-7"><a href="#cb1-7"></a> <<span class="kw">child</span>></span>
|
||
<span id="cb1-8"><a href="#cb1-8"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkScrolledWindow"</span>></span>
|
||
<span id="cb1-9"><a href="#cb1-9"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"hexpand"</span>>TRUE</<span class="kw">property</span>></span>
|
||
<span id="cb1-10"><a href="#cb1-10"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"vexpand"</span>>TRUE</<span class="kw">property</span>></span>
|
||
<span id="cb1-11"><a href="#cb1-11"></a> <<span class="kw">child</span>></span>
|
||
<span id="cb1-12"><a href="#cb1-12"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkColumnView"</span><span class="ot"> id=</span><span class="st">"columnview"</span>></span>
|
||
<span id="cb1-13"><a href="#cb1-13"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"model"</span>></span>
|
||
<span id="cb1-14"><a href="#cb1-14"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkNoSelection"</span>></span>
|
||
<span id="cb1-15"><a href="#cb1-15"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"model"</span>></span>
|
||
<span id="cb1-16"><a href="#cb1-16"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkSortListModel"</span>></span>
|
||
<span id="cb1-17"><a href="#cb1-17"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"model"</span>></span>
|
||
<span id="cb1-18"><a href="#cb1-18"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkDirectoryList"</span><span class="ot"> id=</span><span class="st">"directorylist"</span>></span>
|
||
<span id="cb1-19"><a href="#cb1-19"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"attributes"</span>>standard::name,standard::icon,standard::size,time::modified</<span class="kw">property</span>></span>
|
||
<span id="cb1-20"><a href="#cb1-20"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-21"><a href="#cb1-21"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-22"><a href="#cb1-22"></a> <<span class="kw">binding</span><span class="ot"> name=</span><span class="st">"sorter"</span>></span>
|
||
<span id="cb1-23"><a href="#cb1-23"></a> <<span class="kw">lookup</span><span class="ot"> name=</span><span class="st">"sorter"</span>>columnview</<span class="kw">lookup</span>></span>
|
||
<span id="cb1-24"><a href="#cb1-24"></a> </<span class="kw">binding</span>></span>
|
||
<span id="cb1-25"><a href="#cb1-25"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-26"><a href="#cb1-26"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-27"><a href="#cb1-27"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-28"><a href="#cb1-28"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-29"><a href="#cb1-29"></a> <<span class="kw">child</span>></span>
|
||
<span id="cb1-30"><a href="#cb1-30"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkColumnViewColumn"</span>></span>
|
||
<span id="cb1-31"><a href="#cb1-31"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"title"</span>>Name</<span class="kw">property</span>></span>
|
||
<span id="cb1-32"><a href="#cb1-32"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expand"</span>>TRUE</<span class="kw">property</span>></span>
|
||
<span id="cb1-33"><a href="#cb1-33"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"factory"</span>></span>
|
||
<span id="cb1-34"><a href="#cb1-34"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkBuilderListItemFactory"</span>></span>
|
||
<span id="cb1-35"><a href="#cb1-35"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"bytes"</span>><span class="bn"><![CDATA[</span></span>
|
||
<span id="cb1-36"><a href="#cb1-36"></a><?xml version="1.0" encoding="UTF-8"?></span>
|
||
<span id="cb1-37"><a href="#cb1-37"></a><interface></span>
|
||
<span id="cb1-38"><a href="#cb1-38"></a> <template class="GtkListItem"></span>
|
||
<span id="cb1-39"><a href="#cb1-39"></a> <property name="child"></span>
|
||
<span id="cb1-40"><a href="#cb1-40"></a> <object class="GtkBox"></span>
|
||
<span id="cb1-41"><a href="#cb1-41"></a> <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property></span>
|
||
<span id="cb1-42"><a href="#cb1-42"></a> <property name="spacing">20</property></span>
|
||
<span id="cb1-43"><a href="#cb1-43"></a> <child></span>
|
||
<span id="cb1-44"><a href="#cb1-44"></a> <object class="GtkImage"></span>
|
||
<span id="cb1-45"><a href="#cb1-45"></a> <binding name="gicon"></span>
|
||
<span id="cb1-46"><a href="#cb1-46"></a> <closure type="GIcon" function="get_icon_factory"></span>
|
||
<span id="cb1-47"><a href="#cb1-47"></a> <lookup name="item">GtkListItem</lookup></span>
|
||
<span id="cb1-48"><a href="#cb1-48"></a> </closure></span>
|
||
<span id="cb1-49"><a href="#cb1-49"></a> </binding></span>
|
||
<span id="cb1-50"><a href="#cb1-50"></a> </object></span>
|
||
<span id="cb1-51"><a href="#cb1-51"></a> </child></span>
|
||
<span id="cb1-52"><a href="#cb1-52"></a> <child></span>
|
||
<span id="cb1-53"><a href="#cb1-53"></a> <object class="GtkLabel"></span>
|
||
<span id="cb1-54"><a href="#cb1-54"></a> <property name="hexpand">TRUE</property></span>
|
||
<span id="cb1-55"><a href="#cb1-55"></a> <property name="xalign">0</property></span>
|
||
<span id="cb1-56"><a href="#cb1-56"></a> <binding name="label"></span>
|
||
<span id="cb1-57"><a href="#cb1-57"></a> <closure type="gchararray" function="get_file_name_factory"></span>
|
||
<span id="cb1-58"><a href="#cb1-58"></a> <lookup name="item">GtkListItem</lookup></span>
|
||
<span id="cb1-59"><a href="#cb1-59"></a> </closure></span>
|
||
<span id="cb1-60"><a href="#cb1-60"></a> </binding></span>
|
||
<span id="cb1-61"><a href="#cb1-61"></a> </object></span>
|
||
<span id="cb1-62"><a href="#cb1-62"></a> </child></span>
|
||
<span id="cb1-63"><a href="#cb1-63"></a> </object></span>
|
||
<span id="cb1-64"><a href="#cb1-64"></a> </property></span>
|
||
<span id="cb1-65"><a href="#cb1-65"></a> </template></span>
|
||
<span id="cb1-66"><a href="#cb1-66"></a></interface></span>
|
||
<span id="cb1-67"><a href="#cb1-67"></a> <span class="bn">]]></span></<span class="kw">property</span>></span>
|
||
<span id="cb1-68"><a href="#cb1-68"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-69"><a href="#cb1-69"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-70"><a href="#cb1-70"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sorter"</span>></span>
|
||
<span id="cb1-71"><a href="#cb1-71"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkStringSorter"</span>></span>
|
||
<span id="cb1-72"><a href="#cb1-72"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expression"</span>></span>
|
||
<span id="cb1-73"><a href="#cb1-73"></a> <<span class="kw">closure</span><span class="ot"> type=</span><span class="st">"gchararray"</span><span class="ot"> function=</span><span class="st">"get_file_name"</span>></span>
|
||
<span id="cb1-74"><a href="#cb1-74"></a> </<span class="kw">closure</span>></span>
|
||
<span id="cb1-75"><a href="#cb1-75"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-76"><a href="#cb1-76"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-77"><a href="#cb1-77"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-78"><a href="#cb1-78"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-79"><a href="#cb1-79"></a> </<span class="kw">child</span>></span>
|
||
<span id="cb1-80"><a href="#cb1-80"></a> <<span class="kw">child</span>></span>
|
||
<span id="cb1-81"><a href="#cb1-81"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkColumnViewColumn"</span>></span>
|
||
<span id="cb1-82"><a href="#cb1-82"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"title"</span>>Size</<span class="kw">property</span>></span>
|
||
<span id="cb1-83"><a href="#cb1-83"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"factory"</span>></span>
|
||
<span id="cb1-84"><a href="#cb1-84"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkBuilderListItemFactory"</span>></span>
|
||
<span id="cb1-85"><a href="#cb1-85"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"bytes"</span>><span class="bn"><![CDATA[</span></span>
|
||
<span id="cb1-86"><a href="#cb1-86"></a><?xml version="1.0" encoding="UTF-8"?></span>
|
||
<span id="cb1-87"><a href="#cb1-87"></a><interface></span>
|
||
<span id="cb1-88"><a href="#cb1-88"></a> <template class="GtkListItem"></span>
|
||
<span id="cb1-89"><a href="#cb1-89"></a> <property name="child"></span>
|
||
<span id="cb1-90"><a href="#cb1-90"></a> <object class="GtkLabel"></span>
|
||
<span id="cb1-91"><a href="#cb1-91"></a> <property name="hexpand">TRUE</property></span>
|
||
<span id="cb1-92"><a href="#cb1-92"></a> <property name="xalign">0</property></span>
|
||
<span id="cb1-93"><a href="#cb1-93"></a> <binding name="label"></span>
|
||
<span id="cb1-94"><a href="#cb1-94"></a> <closure type="gint64" function="get_file_size_factory"></span>
|
||
<span id="cb1-95"><a href="#cb1-95"></a> <lookup name="item">GtkListItem</lookup></span>
|
||
<span id="cb1-96"><a href="#cb1-96"></a> </closure></span>
|
||
<span id="cb1-97"><a href="#cb1-97"></a> </binding></span>
|
||
<span id="cb1-98"><a href="#cb1-98"></a> </object></span>
|
||
<span id="cb1-99"><a href="#cb1-99"></a> </property></span>
|
||
<span id="cb1-100"><a href="#cb1-100"></a> </template></span>
|
||
<span id="cb1-101"><a href="#cb1-101"></a></interface></span>
|
||
<span id="cb1-102"><a href="#cb1-102"></a> <span class="bn">]]></span></<span class="kw">property</span>></span>
|
||
<span id="cb1-103"><a href="#cb1-103"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-104"><a href="#cb1-104"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-105"><a href="#cb1-105"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sorter"</span>></span>
|
||
<span id="cb1-106"><a href="#cb1-106"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkNumericSorter"</span>></span>
|
||
<span id="cb1-107"><a href="#cb1-107"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expression"</span>></span>
|
||
<span id="cb1-108"><a href="#cb1-108"></a> <<span class="kw">closure</span><span class="ot"> type=</span><span class="st">"gint64"</span><span class="ot"> function=</span><span class="st">"get_file_size"</span>></span>
|
||
<span id="cb1-109"><a href="#cb1-109"></a> </<span class="kw">closure</span>></span>
|
||
<span id="cb1-110"><a href="#cb1-110"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-111"><a href="#cb1-111"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sort-order"</span>>GTK_SORT_ASCENDING</<span class="kw">property</span>></span>
|
||
<span id="cb1-112"><a href="#cb1-112"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-113"><a href="#cb1-113"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-114"><a href="#cb1-114"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-115"><a href="#cb1-115"></a> </<span class="kw">child</span>></span>
|
||
<span id="cb1-116"><a href="#cb1-116"></a> <<span class="kw">child</span>></span>
|
||
<span id="cb1-117"><a href="#cb1-117"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkColumnViewColumn"</span>></span>
|
||
<span id="cb1-118"><a href="#cb1-118"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"title"</span>>Date modified</<span class="kw">property</span>></span>
|
||
<span id="cb1-119"><a href="#cb1-119"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"factory"</span>></span>
|
||
<span id="cb1-120"><a href="#cb1-120"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkBuilderListItemFactory"</span>></span>
|
||
<span id="cb1-121"><a href="#cb1-121"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"bytes"</span>><span class="bn"><![CDATA[</span></span>
|
||
<span id="cb1-122"><a href="#cb1-122"></a><?xml version="1.0" encoding="UTF-8"?></span>
|
||
<span id="cb1-123"><a href="#cb1-123"></a><interface></span>
|
||
<span id="cb1-124"><a href="#cb1-124"></a> <template class="GtkListItem"></span>
|
||
<span id="cb1-125"><a href="#cb1-125"></a> <property name="child"></span>
|
||
<span id="cb1-126"><a href="#cb1-126"></a> <object class="GtkLabel"></span>
|
||
<span id="cb1-127"><a href="#cb1-127"></a> <property name="hexpand">TRUE</property></span>
|
||
<span id="cb1-128"><a href="#cb1-128"></a> <property name="xalign">0</property></span>
|
||
<span id="cb1-129"><a href="#cb1-129"></a> <binding name="label"></span>
|
||
<span id="cb1-130"><a href="#cb1-130"></a> <closure type="gchararray" function="get_file_time_modified_factory"></span>
|
||
<span id="cb1-131"><a href="#cb1-131"></a> <lookup name="item">GtkListItem</lookup></span>
|
||
<span id="cb1-132"><a href="#cb1-132"></a> </closure></span>
|
||
<span id="cb1-133"><a href="#cb1-133"></a> </binding></span>
|
||
<span id="cb1-134"><a href="#cb1-134"></a> </object></span>
|
||
<span id="cb1-135"><a href="#cb1-135"></a> </property></span>
|
||
<span id="cb1-136"><a href="#cb1-136"></a> </template></span>
|
||
<span id="cb1-137"><a href="#cb1-137"></a></interface></span>
|
||
<span id="cb1-138"><a href="#cb1-138"></a> <span class="bn">]]></span></<span class="kw">property</span>></span>
|
||
<span id="cb1-139"><a href="#cb1-139"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-140"><a href="#cb1-140"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-141"><a href="#cb1-141"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sorter"</span>></span>
|
||
<span id="cb1-142"><a href="#cb1-142"></a> <<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkNumericSorter"</span>></span>
|
||
<span id="cb1-143"><a href="#cb1-143"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expression"</span>></span>
|
||
<span id="cb1-144"><a href="#cb1-144"></a> <<span class="kw">closure</span><span class="ot"> type=</span><span class="st">"gint64"</span><span class="ot"> function=</span><span class="st">"get_file_unixtime_modified"</span>></span>
|
||
<span id="cb1-145"><a href="#cb1-145"></a> </<span class="kw">closure</span>></span>
|
||
<span id="cb1-146"><a href="#cb1-146"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-147"><a href="#cb1-147"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sort-order"</span>>GTK_SORT_ASCENDING</<span class="kw">property</span>></span>
|
||
<span id="cb1-148"><a href="#cb1-148"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-149"><a href="#cb1-149"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb1-150"><a href="#cb1-150"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-151"><a href="#cb1-151"></a> </<span class="kw">child</span>></span>
|
||
<span id="cb1-152"><a href="#cb1-152"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-153"><a href="#cb1-153"></a> </<span class="kw">child</span>></span>
|
||
<span id="cb1-154"><a href="#cb1-154"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-155"><a href="#cb1-155"></a> </<span class="kw">child</span>></span>
|
||
<span id="cb1-156"><a href="#cb1-156"></a> </<span class="kw">object</span>></span>
|
||
<span id="cb1-157"><a href="#cb1-157"></a></<span class="kw">interface</span>></span></code></pre></div>
|
||
<ul>
|
||
<li>3-12: GtkApplicationWindow has a child widget GtkScrolledWindow.
|
||
GtkScrolledWindoww has a child widget GtkColumnView.</li>
|
||
<li>12-18: GtkColumnView has “model” property. It points
|
||
GtkSelectionModel interface. GtkNoSelection class is used as
|
||
GtkSelectionModel. And again, it has “model” property. It points
|
||
GtkSortListModel. This list model supports sorting the list. It will be
|
||
explained in the later subsection. And it also has “model” property. It
|
||
points GtkDirectoryList. Therefore, the chain is: GtkColumnView =>
|
||
GtkNoSelection => GtkSortListModel => GtkDirectoryList.</li>
|
||
<li>18-20: GtkDirectoryList. It is a list of GFileInfo, which holds
|
||
information of files under a directory. It has “attributes” property. It
|
||
specifies what attributes is kept in each GFileInfo.
|
||
<ul>
|
||
<li>“standard::name” is a name of the file.</li>
|
||
<li>“standard::icon” is a GIcon object of the file</li>
|
||
<li>“standard::size” is the file size.</li>
|
||
<li>“time::modified” is the date and time the file was last
|
||
modified.</li>
|
||
</ul></li>
|
||
<li>29-79: The first GtkColumnViewColumn object. There are four
|
||
properties, “title”, “expand”, factory” and “sorter”.</li>
|
||
<li>31: Sets the “title” property to “Name”. This is the title on the
|
||
header of the column.</li>
|
||
<li>32: Sets the “expand” property to TRUE to allow the column to expand
|
||
as much as possible. (See the image above).</li>
|
||
<li>33- 69: Sets the “factory” property to GtkBuilderListItemFactory.
|
||
The factory has “bytes” property which holds a ui string to define a
|
||
template to extend GtkListItem class. The CDATA section (line 36-66) is
|
||
the ui string to put into the “bytes” property. The contents are the
|
||
same as the ui file <code>factory_list.ui</code> in the section 30.</li>
|
||
<li>70-77: Sets the “sorter” property to GtkStringSorter object. This
|
||
object provides a sorter that compares strings. It has “expression”
|
||
property. A closure tag with a string type function
|
||
<code>get_file_name</code> is used here. The function will be explained
|
||
later.</li>
|
||
<li>80-115: The second GtkColumnViewColumn object. Its sorter property
|
||
is set to GtkNumericSorter.</li>
|
||
<li>116-151: The third GtkColumnViewColumn object. Its sorter property
|
||
is set to GtkNumericSorter.</li>
|
||
</ul>
|
||
<h2 id="gtksortlistmodel-and-gtksorter">GtkSortListModel and
|
||
GtkSorter</h2>
|
||
<p>GtkSortListModel is a list model that sorts its elements according to
|
||
a GtkSorter instance assigned to the “sorter” property. The property is
|
||
bound to “sorter” property of GtkColumnView in line 22 to 24.</p>
|
||
<div class="sourceCode" id="cb2"><pre
|
||
class="sourceCode xml"><code class="sourceCode xml"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkSortListModel"</span><span class="ot"> id=</span><span class="st">"sortlist"</span>></span>
|
||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>... ... ...</span>
|
||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">binding</span><span class="ot"> name=</span><span class="st">"sorter"</span>></span>
|
||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <<span class="kw">lookup</span><span class="ot"> name=</span><span class="st">"sorter"</span>>columnview</<span class="kw">lookup</span>></span>
|
||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> </<span class="kw">binding</span>></span></code></pre></div>
|
||
<p>Therefore, <code>columnview</code> determines the way how to sort the
|
||
list model. The “sorter” property of GtkColumnView is read-only property
|
||
and it is a special sorter. It reflects the user’s sorting choice. If a
|
||
user clicks the header of a column, then the sorter (“sorter” property)
|
||
of the column is referenced by “sorter” property of the GtkColumnView.
|
||
If the user clicks the header of another column, then the “sorter”
|
||
property of the GtkColumnView refers to the newly clicked column’s
|
||
“sorter” property.</p>
|
||
<p>The binding above makes a indirect connection between the “sorter”
|
||
property of GtkSortListModel and the “sorter” property of each
|
||
column.</p>
|
||
<p>GtkSorter compares two items (GObject or its descendant). GtkSorter
|
||
has several child objects.</p>
|
||
<ul>
|
||
<li>GtkStringSorter compares strings taken from the items.</li>
|
||
<li>GtkNumericSorter compares numbers taken from the items.</li>
|
||
<li>GtkCustomSorter uses a callback to compare.</li>
|
||
<li>GtkMultiSorter combines multiple sorters.</li>
|
||
</ul>
|
||
<p>The example uses GtkStringSorter and GtkNumericSorter.</p>
|
||
<p>GtkStringSorter uses GtkExpression to get the strings from the items
|
||
(objects). The GtkExpression is stored in the “expression” property of
|
||
the GtkStringSorter. When GtkStringSorter compares two items, it
|
||
evaluates the expression by calling <code>gtk_expression_evaluate</code>
|
||
function. It assigns each item to the second argument (‘this’ object) of
|
||
the function.</p>
|
||
<p>In the ui file above, the GtkExpression is in the line 71 to 76.</p>
|
||
<div class="sourceCode" id="cb3"><pre
|
||
class="sourceCode xml"><code class="sourceCode xml"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkStringSorter"</span>></span>
|
||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expression"</span>></span>
|
||
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">closure</span><span class="ot"> type=</span><span class="st">"gchararray"</span><span class="ot"> function=</span><span class="st">"get_file_name"</span>></span>
|
||
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> </<span class="kw">closure</span>></span>
|
||
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></<span class="kw">object</span>></span></code></pre></div>
|
||
<p>The GtkExpression calls <code>get_file_name</code> function when it
|
||
is evaluated.</p>
|
||
<div class="sourceCode" id="cb4"><pre
|
||
class="sourceCode numberSource C numberLines"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1"></a><span class="dt">char</span> <span class="op">*</span></span>
|
||
<span id="cb4-2"><a href="#cb4-2"></a>get_file_name <span class="op">(</span>GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb4-3"><a href="#cb4-3"></a> <span class="cf">return</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_strdup<span class="op">(</span>g_file_info_get_name <span class="op">(</span>info<span class="op">))</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb4-4"><a href="#cb4-4"></a><span class="op">}</span></span></code></pre></div>
|
||
<p>The function is given the item (GFileInfo) of the GtkSortListModel as
|
||
an argument (<code>this</code> object). But you need to be careful that
|
||
it can be NULL while the list item is being recycled. So,
|
||
<code>G_IS_FILE_INFO (info)</code> is always necessary in callback
|
||
functions. The function retrieves a filename from <code>info</code>. The
|
||
string is owned by <code>info</code> so it is necessary to duplicate it.
|
||
And it returns the copied string.</p>
|
||
<p>GtkNumericSorter compares numbers. It is used in the line 106 to 112
|
||
and line 142 to 148. The lines from 106 to 112 is:</p>
|
||
<div class="sourceCode" id="cb5"><pre
|
||
class="sourceCode xml"><code class="sourceCode xml"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkNumericSorter"</span>></span>
|
||
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expression"</span>></span>
|
||
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">closure</span><span class="ot"> type=</span><span class="st">"gint64"</span><span class="ot"> function=</span><span class="st">"get_file_size"</span>></span>
|
||
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> </<span class="kw">closure</span>></span>
|
||
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sort-order"</span>>GTK_SORT_ASCENDING</<span class="kw">property</span>></span>
|
||
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a></<span class="kw">object</span>></span></code></pre></div>
|
||
<p>The closure tag specifies a callback function
|
||
<code>get_file_size</code>.</p>
|
||
<div class="sourceCode" id="cb6"><pre
|
||
class="sourceCode numberSource C numberLines"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1"></a>goffset</span>
|
||
<span id="cb6-2"><a href="#cb6-2"></a>get_file_size <span class="op">(</span>GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb6-3"><a href="#cb6-3"></a> <span class="cf">return</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_size <span class="op">(</span>info<span class="op">):</span> <span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||
<span id="cb6-4"><a href="#cb6-4"></a><span class="op">}</span></span></code></pre></div>
|
||
<p>It just returns the size of <code>info</code>. The type of the size
|
||
is <code>goffset</code>. The type <code>goffset</code> is the same as
|
||
<code>gint64</code>.</p>
|
||
<p>The lines from 142 to 148 is:</p>
|
||
<div class="sourceCode" id="cb7"><pre
|
||
class="sourceCode xml"><code class="sourceCode xml"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">object</span><span class="ot"> class=</span><span class="st">"GtkNumericSorter"</span><span class="ot"> id=</span><span class="st">"sorter_datetime_modified"</span>></span>
|
||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"expression"</span>></span>
|
||
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">closure</span><span class="ot"> type=</span><span class="st">"gint64"</span><span class="ot"> function=</span><span class="st">"get_file_unixtime_modified"</span>></span>
|
||
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> </<span class="kw">closure</span>></span>
|
||
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> </<span class="kw">property</span>></span>
|
||
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <<span class="kw">property</span><span class="ot"> name=</span><span class="st">"sort-order"</span>>GTK_SORT_ASCENDING</<span class="kw">property</span>></span>
|
||
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a></<span class="kw">object</span>></span></code></pre></div>
|
||
<p>The closure tag specifies a callback function
|
||
<code>get_file_unixtime_modified</code>.</p>
|
||
<div class="sourceCode" id="cb8"><pre
|
||
class="sourceCode numberSource C numberLines"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1"></a>gint64</span>
|
||
<span id="cb8-2"><a href="#cb8-2"></a>get_file_unixtime_modified <span class="op">(</span>GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb8-3"><a href="#cb8-3"></a> GDateTime <span class="op">*</span>dt<span class="op">;</span></span>
|
||
<span id="cb8-4"><a href="#cb8-4"></a></span>
|
||
<span id="cb8-5"><a href="#cb8-5"></a> dt <span class="op">=</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_modification_date_time <span class="op">(</span>info<span class="op">)</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb8-6"><a href="#cb8-6"></a> <span class="cf">return</span> dt <span class="op">?</span> g_date_time_to_unix <span class="op">(</span>dt<span class="op">)</span> <span class="op">:</span> <span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||
<span id="cb8-7"><a href="#cb8-7"></a><span class="op">}</span></span></code></pre></div>
|
||
<p>It gets the modification date and time (GDateTime type) of
|
||
<code>info</code>. Then it gets a unix time from <code>dt</code>. Unix
|
||
time, sometimes called unix epoch, is the number of seconds that have
|
||
elapsed since 00:00:00 UTC on 1 January 1970. It returns the unix time
|
||
(gint64 type).</p>
|
||
<h2 id="column.c">column.c</h2>
|
||
<p><code>column.c</code> is as follows. It is simple and short thanks to
|
||
<code>column.ui</code>.</p>
|
||
<div class="sourceCode" id="cb9"><pre
|
||
class="sourceCode numberSource C numberLines"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1"></a><span class="pp">#include </span><span class="im"><gtk/gtk.h></span></span>
|
||
<span id="cb9-2"><a href="#cb9-2"></a></span>
|
||
<span id="cb9-3"><a href="#cb9-3"></a><span class="co">/* functions (closures) for GtkBuilderListItemFactory */</span></span>
|
||
<span id="cb9-4"><a href="#cb9-4"></a>GIcon <span class="op">*</span></span>
|
||
<span id="cb9-5"><a href="#cb9-5"></a>get_icon_factory <span class="op">(</span>GtkListItem <span class="op">*</span>item<span class="op">,</span> GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-6"><a href="#cb9-6"></a> GIcon <span class="op">*</span>icon<span class="op">;</span></span>
|
||
<span id="cb9-7"><a href="#cb9-7"></a></span>
|
||
<span id="cb9-8"><a href="#cb9-8"></a> <span class="co">/* g_file_info_get_icon can return NULL */</span></span>
|
||
<span id="cb9-9"><a href="#cb9-9"></a> icon <span class="op">=</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_icon <span class="op">(</span>info<span class="op">)</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-10"><a href="#cb9-10"></a> <span class="cf">return</span> icon <span class="op">?</span> g_object_ref <span class="op">(</span>icon<span class="op">)</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-11"><a href="#cb9-11"></a><span class="op">}</span></span>
|
||
<span id="cb9-12"><a href="#cb9-12"></a></span>
|
||
<span id="cb9-13"><a href="#cb9-13"></a><span class="dt">char</span> <span class="op">*</span></span>
|
||
<span id="cb9-14"><a href="#cb9-14"></a>get_file_name_factory <span class="op">(</span>GtkListItem <span class="op">*</span>item<span class="op">,</span> GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-15"><a href="#cb9-15"></a> <span class="cf">return</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_strdup <span class="op">(</span>g_file_info_get_name <span class="op">(</span>info<span class="op">))</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-16"><a href="#cb9-16"></a><span class="op">}</span></span>
|
||
<span id="cb9-17"><a href="#cb9-17"></a></span>
|
||
<span id="cb9-18"><a href="#cb9-18"></a><span class="co">/* goffset is defined as gint64 */</span></span>
|
||
<span id="cb9-19"><a href="#cb9-19"></a><span class="co">/* It is used for file offsets. */</span></span>
|
||
<span id="cb9-20"><a href="#cb9-20"></a>goffset</span>
|
||
<span id="cb9-21"><a href="#cb9-21"></a>get_file_size_factory <span class="op">(</span>GtkListItem <span class="op">*</span>item<span class="op">,</span> GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-22"><a href="#cb9-22"></a> <span class="cf">return</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_size <span class="op">(</span>info<span class="op">)</span> <span class="op">:</span> <span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||
<span id="cb9-23"><a href="#cb9-23"></a><span class="op">}</span></span>
|
||
<span id="cb9-24"><a href="#cb9-24"></a></span>
|
||
<span id="cb9-25"><a href="#cb9-25"></a><span class="dt">char</span> <span class="op">*</span></span>
|
||
<span id="cb9-26"><a href="#cb9-26"></a>get_file_time_modified_factory <span class="op">(</span>GtkListItem <span class="op">*</span>item<span class="op">,</span> GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-27"><a href="#cb9-27"></a> GDateTime <span class="op">*</span>dt<span class="op">;</span></span>
|
||
<span id="cb9-28"><a href="#cb9-28"></a></span>
|
||
<span id="cb9-29"><a href="#cb9-29"></a> <span class="co">/* g_file_info_get_modification_date_time can return NULL */</span></span>
|
||
<span id="cb9-30"><a href="#cb9-30"></a> dt <span class="op">=</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_modification_date_time <span class="op">(</span>info<span class="op">)</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-31"><a href="#cb9-31"></a> <span class="cf">return</span> dt <span class="op">?</span> g_date_time_format <span class="op">(</span>dt<span class="op">,</span> <span class="st">"%F"</span><span class="op">)</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-32"><a href="#cb9-32"></a><span class="op">}</span></span>
|
||
<span id="cb9-33"><a href="#cb9-33"></a></span>
|
||
<span id="cb9-34"><a href="#cb9-34"></a><span class="co">/* Functions (closures) for GtkSorter */</span></span>
|
||
<span id="cb9-35"><a href="#cb9-35"></a><span class="dt">char</span> <span class="op">*</span></span>
|
||
<span id="cb9-36"><a href="#cb9-36"></a>get_file_name <span class="op">(</span>GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-37"><a href="#cb9-37"></a> <span class="cf">return</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_strdup<span class="op">(</span>g_file_info_get_name <span class="op">(</span>info<span class="op">))</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-38"><a href="#cb9-38"></a><span class="op">}</span></span>
|
||
<span id="cb9-39"><a href="#cb9-39"></a></span>
|
||
<span id="cb9-40"><a href="#cb9-40"></a>goffset</span>
|
||
<span id="cb9-41"><a href="#cb9-41"></a>get_file_size <span class="op">(</span>GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-42"><a href="#cb9-42"></a> <span class="cf">return</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_size <span class="op">(</span>info<span class="op">):</span> <span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||
<span id="cb9-43"><a href="#cb9-43"></a><span class="op">}</span></span>
|
||
<span id="cb9-44"><a href="#cb9-44"></a></span>
|
||
<span id="cb9-45"><a href="#cb9-45"></a>gint64</span>
|
||
<span id="cb9-46"><a href="#cb9-46"></a>get_file_unixtime_modified <span class="op">(</span>GFileInfo <span class="op">*</span>info<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-47"><a href="#cb9-47"></a> GDateTime <span class="op">*</span>dt<span class="op">;</span></span>
|
||
<span id="cb9-48"><a href="#cb9-48"></a></span>
|
||
<span id="cb9-49"><a href="#cb9-49"></a> dt <span class="op">=</span> G_IS_FILE_INFO <span class="op">(</span>info<span class="op">)</span> <span class="op">?</span> g_file_info_get_modification_date_time <span class="op">(</span>info<span class="op">)</span> <span class="op">:</span> NULL<span class="op">;</span></span>
|
||
<span id="cb9-50"><a href="#cb9-50"></a> <span class="cf">return</span> dt <span class="op">?</span> g_date_time_to_unix <span class="op">(</span>dt<span class="op">)</span> <span class="op">:</span> <span class="op">-</span><span class="dv">1</span><span class="op">;</span></span>
|
||
<span id="cb9-51"><a href="#cb9-51"></a><span class="op">}</span></span>
|
||
<span id="cb9-52"><a href="#cb9-52"></a></span>
|
||
<span id="cb9-53"><a href="#cb9-53"></a><span class="dt">static</span> <span class="dt">void</span></span>
|
||
<span id="cb9-54"><a href="#cb9-54"></a>app_activate <span class="op">(</span>GApplication <span class="op">*</span>application<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-55"><a href="#cb9-55"></a> GtkApplication <span class="op">*</span>app <span class="op">=</span> GTK_APPLICATION <span class="op">(</span>application<span class="op">);</span></span>
|
||
<span id="cb9-56"><a href="#cb9-56"></a> gtk_window_present <span class="op">(</span>gtk_application_get_active_window<span class="op">(</span>app<span class="op">));</span></span>
|
||
<span id="cb9-57"><a href="#cb9-57"></a><span class="op">}</span></span>
|
||
<span id="cb9-58"><a href="#cb9-58"></a></span>
|
||
<span id="cb9-59"><a href="#cb9-59"></a><span class="dt">static</span> <span class="dt">void</span></span>
|
||
<span id="cb9-60"><a href="#cb9-60"></a>app_startup <span class="op">(</span>GApplication <span class="op">*</span>application<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-61"><a href="#cb9-61"></a> GtkApplication <span class="op">*</span>app <span class="op">=</span> GTK_APPLICATION <span class="op">(</span>application<span class="op">);</span></span>
|
||
<span id="cb9-62"><a href="#cb9-62"></a> GFile <span class="op">*</span>file<span class="op">;</span></span>
|
||
<span id="cb9-63"><a href="#cb9-63"></a> GtkBuilder <span class="op">*</span>build <span class="op">=</span> gtk_builder_new_from_resource <span class="op">(</span><span class="st">"/com/github/ToshioCP/column/column.ui"</span><span class="op">);</span></span>
|
||
<span id="cb9-64"><a href="#cb9-64"></a> GtkWidget <span class="op">*</span>win <span class="op">=</span> GTK_WIDGET <span class="op">(</span>gtk_builder_get_object <span class="op">(</span>build<span class="op">,</span> <span class="st">"win"</span><span class="op">));</span></span>
|
||
<span id="cb9-65"><a href="#cb9-65"></a> GtkDirectoryList <span class="op">*</span>directorylist <span class="op">=</span> GTK_DIRECTORY_LIST <span class="op">(</span>gtk_builder_get_object <span class="op">(</span>build<span class="op">,</span> <span class="st">"directorylist"</span><span class="op">));</span></span>
|
||
<span id="cb9-66"><a href="#cb9-66"></a> g_object_unref <span class="op">(</span>build<span class="op">);</span></span>
|
||
<span id="cb9-67"><a href="#cb9-67"></a></span>
|
||
<span id="cb9-68"><a href="#cb9-68"></a> gtk_window_set_application <span class="op">(</span>GTK_WINDOW <span class="op">(</span>win<span class="op">),</span> app<span class="op">);</span></span>
|
||
<span id="cb9-69"><a href="#cb9-69"></a></span>
|
||
<span id="cb9-70"><a href="#cb9-70"></a> file <span class="op">=</span> g_file_new_for_path <span class="op">(</span><span class="st">"."</span><span class="op">);</span></span>
|
||
<span id="cb9-71"><a href="#cb9-71"></a> gtk_directory_list_set_file <span class="op">(</span>directorylist<span class="op">,</span> file<span class="op">);</span></span>
|
||
<span id="cb9-72"><a href="#cb9-72"></a> g_object_unref <span class="op">(</span>file<span class="op">);</span></span>
|
||
<span id="cb9-73"><a href="#cb9-73"></a><span class="op">}</span></span>
|
||
<span id="cb9-74"><a href="#cb9-74"></a></span>
|
||
<span id="cb9-75"><a href="#cb9-75"></a><span class="pp">#define APPLICATION_ID "com.github.ToshioCP.columnview"</span></span>
|
||
<span id="cb9-76"><a href="#cb9-76"></a></span>
|
||
<span id="cb9-77"><a href="#cb9-77"></a><span class="dt">int</span></span>
|
||
<span id="cb9-78"><a href="#cb9-78"></a>main <span class="op">(</span><span class="dt">int</span> argc<span class="op">,</span> <span class="dt">char</span> <span class="op">**</span>argv<span class="op">)</span> <span class="op">{</span></span>
|
||
<span id="cb9-79"><a href="#cb9-79"></a> GtkApplication <span class="op">*</span>app<span class="op">;</span></span>
|
||
<span id="cb9-80"><a href="#cb9-80"></a> <span class="dt">int</span> stat<span class="op">;</span></span>
|
||
<span id="cb9-81"><a href="#cb9-81"></a></span>
|
||
<span id="cb9-82"><a href="#cb9-82"></a> app <span class="op">=</span> gtk_application_new <span class="op">(</span>APPLICATION_ID<span class="op">,</span> G_APPLICATION_DEFAULT_FLAGS<span class="op">);</span></span>
|
||
<span id="cb9-83"><a href="#cb9-83"></a></span>
|
||
<span id="cb9-84"><a href="#cb9-84"></a> g_signal_connect <span class="op">(</span>app<span class="op">,</span> <span class="st">"startup"</span><span class="op">,</span> G_CALLBACK <span class="op">(</span>app_startup<span class="op">),</span> NULL<span class="op">);</span></span>
|
||
<span id="cb9-85"><a href="#cb9-85"></a> g_signal_connect <span class="op">(</span>app<span class="op">,</span> <span class="st">"activate"</span><span class="op">,</span> G_CALLBACK <span class="op">(</span>app_activate<span class="op">),</span> NULL<span class="op">);</span></span>
|
||
<span id="cb9-86"><a href="#cb9-86"></a></span>
|
||
<span id="cb9-87"><a href="#cb9-87"></a> stat <span class="op">=</span>g_application_run <span class="op">(</span>G_APPLICATION <span class="op">(</span>app<span class="op">),</span> argc<span class="op">,</span> argv<span class="op">);</span></span>
|
||
<span id="cb9-88"><a href="#cb9-88"></a> g_object_unref <span class="op">(</span>app<span class="op">);</span></span>
|
||
<span id="cb9-89"><a href="#cb9-89"></a> <span class="cf">return</span> stat<span class="op">;</span></span>
|
||
<span id="cb9-90"><a href="#cb9-90"></a><span class="op">}</span></span></code></pre></div>
|
||
<h2 id="compilation-and-execution.">Compilation and execution.</h2>
|
||
<p>All the source files are in <code>src/column</code> directory. Change
|
||
your current directory to the directory and type the following.</p>
|
||
<pre><code>$ cd src/colomn
|
||
$ meson setup _build
|
||
$ ninja -C _build
|
||
$ _build/column</code></pre>
|
||
<p>Then, a window appears.</p>
|
||
<figure>
|
||
<img src="image/column_view.png" alt="Column View" />
|
||
<figcaption aria-hidden="true">Column View</figcaption>
|
||
</figure>
|
||
<p>If you click the header of a column, then the whole lists are sorted
|
||
by the column. If you click the header of another column, then the whole
|
||
lists are sorted by the newly selected column.</p>
|
||
<p>GtkColumnView is very useful and it can manage very big GListModel.
|
||
It is possible to use it for file list, application list, database
|
||
frontend and so on.</p>
|
||
</div>
|
||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
||
</body>
|
||
</html>
|