From: yocto Date: Mon, 15 Aug 2011 08:47:20 +0000 (+0900) Subject: Ver. 0.3 X-Git-Url: http://git.osdn.net/view?p=gpet%2Forigin.git;a=commitdiff_plain;h=7d50fb9e6ba61569ca4cccf8d98813827bd09a3e Ver. 0.3 --- diff --git a/ChangeLog b/ChangeLog index 5e0b23c..1638b4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2011/06/18 yocto + + 0.3 Released + + * Enter key is enabled in the dialog box + Domain window: profile list dialog + Profile window: profile edit dialog + Domain, ACL, Exception, Profile, Manager window: add dialog + + * Search dialog enhancement + Match case + Wrap around + Close dialog + + * Path name displayed as it is. + Domain, ACL, Exception window: display, search, add + The command name of the Process window is still octal. + When space and multi byte character, etc. are included in the path name + input by an additional dialog, it encloses it with single quotation [']. + Single quotes in the path name ['] may contain escaped with a backslash + [\'] should be. + + * Statistics window display was changed to display the local date and time. + + * Added support for copy of the cursor line.(Profile window) + + * Added a toolbar to the Manager window. + + * Added a toolbar and Apply button to the Statistics window. + + 2011/04/25 yocto 0.2.1 Update @@ -28,14 +59,14 @@ * Added support for Extraction of redundant ACL entries. Ctrl+O - * Added support for copy of the cursor line.(domain、ACL、exception) + * Added support for copy of the cursor line.(Domain, ACL, Exception window) Ctrl+C * Added support for search dialog. -2011/04/23 yocto +2010/12/18 yocto 0.1 Released diff --git a/ChangeLog.ja b/ChangeLog.ja new file mode 100644 index 0000000..2bdf8d6 --- /dev/null +++ b/ChangeLog.ja @@ -0,0 +1,77 @@ +2011/06/18 yocto + + 0.3 Released + + * ダイアログでのenter key有効化 + domainウィンドウ:プロファイル設定ダイアログ + profileウィンドウ:プロファイル変更ダイアログ + domain, ACL, exception, profile, managerウィンドウ:追加ダイアログ + + * 検索ダイアログに機能追加 + 大文字と小文字を区別する (M)atch case + 折返しも対象にする (W)rap around + enterで閉じる Close (d)ialog + + * パス名の漢字等をそのまま表示 + domain, ACL, exceptionウィンドウの表示、検索、追加で有効 + processウィンドウのコマンド名は8進表記のまま + 追加ダイアログで入力するパス名にスペースや漢字等が含まれる場合は + シングルクォーテーション[']で囲む + パス名に[']が含まれる場合は\エスケープ[\']する + + * Statisticsの日時をローカルタイム表示に変更 + + * カーソル行データコピーを追加:profile + + * managerウィンドウにツールバーを追加 + + * Statisticsウィンドウにツールバー、適用ボタンを追加 + + +2011/04/25 yocto + + 0.2.1 Update + + * ドキュメントのインストールディレクトリを + 「/usr/doc/gpet/」から「/usr/share/doc/gpet/」に修正 + + +2011/04/23 yocto + + 0.2 Released + + * ベースとなるccs-editpolicyをccstools 1.8.1 20110401版 に変更 + + * ACLウィンドウの切離し機能を追加 + メニュー > 表示 > ACLウィンドウ切離し + + * メニューの memory usage を Statistics に変更 + ショーカットキー Ctrl+U を Ctrl+S に変更 + + * オフラインモードとネットワークモードに対応 + 現状はccs-editpolicy同様、起動引数で指定です。 + + * フォント及び色のリソースファイルに対応 gpetrc.sample 追加 + 下記のようにコピーして中身を変更してください + cp /usr/share/doc/gpetrc.sample ~/.gpetrc + + * プロセスモードのショーカットキーを Ctrl+O から Ctrl+@ に変更 + + * ACLの冗長エントリ抽出(パターン化支援)機能を追加 + ショーカットキー Ctrl+O + + * ウィンドウキャプションにモード表示を追加 + + * エントリ追加時にカーソルを追加項目に移動するように変更 + + * カーソル行データコピー domain、ACL、exception + コピー時にクリップボード(OSバッファ)にもコピーする + + * ダイアログ検索を追加 domain、ACL、exception、profile + + +2010/12/18 yocto + + 0.1 Released + + * 初期リリース diff --git a/INSTALL b/INSTALL index ff17dce..c551c15 100644 --- a/INSTALL +++ b/INSTALL @@ -1,4 +1,4 @@ -gpet 0.2.1 2011-04-25 +gpet 0.3 2011-06-18 gpet (Gui Policy Editor for TOMOYO Linux) Build / Install / Run / Uninstall @@ -8,9 +8,9 @@ $ sudo apt-get install gcc make libncurses-dev $ sudo apt-get install intltool libgtk2.0-dev libgconf2-dev -$ tar xjvf gpet-0.2.1.tar.bz2 +$ tar xjvf gpet-0.3.tar.bz2 -$ cd gpet-0.2.1 +$ cd gpet-0.3 $ ./configure --prefix /usr $ make @@ -37,26 +37,26 @@ $ cp /usr/share/doc/gpet/gpetrc.sample ~/.gpetrc *** Instll location *** -/usr -├── doc -│   └── gpet -│   ├── AUTHORS -│   ├── COPYING -│   ├── ChangeLog -│   ├── INSTALL -│   ├── NEWS -│   ├── README -│   └── gpetrc.sample -├── sbin -│   └── gpet -└── share - ├── gpet - │   └── pixmaps - │   └── tomoyo.png - └── locale - └── ja - └── LC_MESSAGES - └── gpet.mo +|-- sbin +| `-- gpet +`-- share + |-- doc + | `-- gpet + | |-- AUTHORS + | |-- COPYING + | |-- ChangeLog + | |-- ChangeLog.ja + | |-- INSTALL + | |-- NEWS + | |-- README + | `-- gpetrc.sample + |-- gpet + | `-- pixmaps + | `-- tomoyo.png + `-- locale + `-- ja + `-- LC_MESSAGES + `-- gpet.mo *** Uninstall *** diff --git a/Makefile.am b/Makefile.am index ef82ca0..1b92a7e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,7 @@ gpetdoc_DATA = \ COPYING\ AUTHORS\ ChangeLog\ - ChangeLog.jp\ + ChangeLog.ja\ INSTALL\ NEWS\ gpetrc.sample diff --git a/configure.ac b/configure.ac index 96a36ff..3f5b845 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. dnl Created by Anjuta application wizard. -AC_INIT(gpet, 0.2.1) +AC_INIT(gpet, 0.3) __GPET=gpet AC_SUBST(__GPET) diff --git a/po/ja.po b/po/ja.po index 41835d5..1a28b73 100644 --- a/po/ja.po +++ b/po/ja.po @@ -8,8 +8,8 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-04-22 23:05+0900\n" -"PO-Revision-Date: 2011-04-22 23:04+0900\n" +"POT-Creation-Date: 2011-06-10 13:56+0900\n" +"PO-Revision-Date: 2011-06-10 13:56+0900\n" "Last-Translator: Yoshihiro Kusuno \n" "Language-Team: Japanese < >\n" "Language: \n" @@ -17,44 +17,44 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: ../src/gpet.c:1135 +#: ../src/gpet.c:1193 msgid "offline" msgstr "オフライン" -#: ../src/gpet.c:1135 +#: ../src/gpet.c:1193 msgid "nework" msgstr "ネットワーク" -#: ../src/gpet.c:1135 +#: ../src/gpet.c:1193 msgid "online" msgstr "オンライン" -#: ../src/gpet.c:1179 ../src/gpet.c:1184 ../src/menu.c:79 +#: ../src/gpet.c:1237 ../src/gpet.c:1242 ../src/menu.c:79 msgid "Statistics" msgstr "統計情報" -#: ../src/gpet.c:1190 ../src/gpet.c:1194 ../src/gpet.c:1199 +#: ../src/gpet.c:1248 ../src/gpet.c:1252 ../src/gpet.c:1257 msgid "Manager Policy" msgstr "マネージャ 一覧" -#: ../src/gpet.c:1205 ../src/gpet.c:1209 ../src/gpet.c:1214 +#: ../src/gpet.c:1263 ../src/gpet.c:1267 ../src/gpet.c:1272 msgid "Domain Policy Editor" msgstr "ドメインポリシーエディタ" -#: ../src/gpet.c:1385 ../src/gpet.c:1410 +#: ../src/gpet.c:1443 ../src/gpet.c:1468 msgid "gpet" msgstr "gpet" #. create tab -#: ../src/gpet.c:1517 ../src/menu.c:352 +#: ../src/gpet.c:1575 ../src/menu.c:469 msgid "Domain Transition" msgstr "ドメイン遷移 一覧" -#: ../src/gpet.c:1518 +#: ../src/gpet.c:1576 msgid "Exception Policy" msgstr "例外ポリシー 一覧" -#: ../src/gpet.c:1519 +#: ../src/gpet.c:1577 msgid "Profile" msgstr "プロファイル 一覧" @@ -62,7 +62,7 @@ msgstr "プロファイル 一覧" msgid "_File" msgstr "ファイル(_F)" -#: ../src/menu.c:47 ../src/other.c:47 +#: ../src/menu.c:47 ../src/other.c:48 msgid "_Edit" msgstr "編集(_E)" @@ -90,19 +90,19 @@ msgstr "編集(_E)" msgid "Set or Edit the selected line" msgstr "選択した行を修正します。" -#: ../src/menu.c:56 ../src/other.c:49 +#: ../src/menu.c:56 ../src/other.c:50 msgid "_Add" msgstr "追加(_A)" -#: ../src/menu.c:57 ../src/other.c:50 +#: ../src/menu.c:57 ../src/other.c:51 msgid "Append line" msgstr "追加します。" -#: ../src/menu.c:58 ../src/other.c:51 +#: ../src/menu.c:58 ../src/other.c:52 msgid "_Delete" msgstr "削除(_D)" -#: ../src/menu.c:59 ../src/other.c:52 +#: ../src/menu.c:59 ../src/other.c:53 msgid "Delete the selected line" msgstr "選択した行を削除します。" @@ -123,8 +123,8 @@ msgid "Extraction of redundant ACL entries" msgstr "冗長なACLエントリを削除するためのサポートをします。" #: ../src/menu.c:67 -msgid "_Search" -msgstr "検索(_S)" +msgid "_Search..." +msgstr "検索...(_S)" #: ../src/menu.c:68 msgid "Search for text" @@ -155,16 +155,16 @@ msgid "Refresh to the latest information" msgstr "再読み込みを行います。" #: ../src/menu.c:76 -msgid "_Manager" -msgstr "マネージャ(_M)" +msgid "_Manager..." +msgstr "マネージャ...(_M)" #: ../src/menu.c:77 msgid "Manager Profile Editor" msgstr "マネージャ 一覧" #: ../src/menu.c:78 -msgid "_Statistics" -msgstr "統計情報(_S)" +msgid "_Statistics..." +msgstr "統計情報...(_S)" #: ../src/menu.c:81 msgid "_About" @@ -190,11 +190,11 @@ msgstr "ACLウィンドウ切離し" msgid "Detach ACL window" msgstr "ドメインポリシーを別ウィンドウで表示します。" -#: ../src/menu.c:349 +#: ../src/menu.c:466 msgid "Process State" msgstr "プロセス 一覧" -#: ../src/menu.c:627 +#: ../src/menu.c:748 #, c-format msgid "" "Delete the %d selected " @@ -203,7 +203,7 @@ msgstr "" "選択した %d行の例外ポリシーを削除します。" -#: ../src/menu.c:630 +#: ../src/menu.c:751 #, c-format msgid "" "Delete the selected exception " @@ -212,7 +212,7 @@ msgstr "" "選択した 例外ポリシーを削除しま" "す。" -#: ../src/menu.c:647 +#: ../src/menu.c:768 #, c-format msgid "" "Delete the %d selected domains?" @@ -221,7 +221,7 @@ msgstr "" "選択した %d行のドメインを削除し" "ます。" -#: ../src/menu.c:650 +#: ../src/menu.c:771 #, c-format msgid "" "Delete the selected domain?選択した ドメインを削除します。" "" -#: ../src/menu.c:669 +#: ../src/menu.c:790 #, c-format msgid "" "Delete the %d selected " @@ -239,7 +239,7 @@ msgstr "" "選択した %d行のポリシーを削除し" "ます。" -#: ../src/menu.c:672 +#: ../src/menu.c:793 #, c-format msgid "" "Delete the selected policy?選択した ポリシーを削除します。" "" -#: ../src/menu.c:813 +#: ../src/menu.c:1027 msgid "Add Domain" msgstr "ドメインを追加します。" -#: ../src/menu.c:820 +#: ../src/menu.c:1034 msgid "Add Acl" msgstr "ドメインに対するアクセス許可を追加します。" -#: ../src/menu.c:832 +#: ../src/menu.c:1046 msgid "Add Exception" msgstr "例外ポリシーを追加します。" -#: ../src/menu.c:840 +#: ../src/menu.c:1054 msgid "Add Profile (0 - 255)" msgstr "プロファイルを追加します。 (0 - 255)" -#: ../src/menu.c:976 +#: ../src/menu.c:1196 msgid "Profile list" msgstr "プロファイルを選択します。" -#: ../src/menu.c:1039 +#: ../src/menu.c:1271 msgid "Profile Edit" msgstr "プロファイルを変更します。" -#: ../src/menu.c:1120 +#: ../src/menu.c:1355 msgid "Yoshihiro Kusuno " msgstr "楠野 佳宏 " -#: ../src/menu.c:1121 +#: ../src/menu.c:1356 msgid "ccstools --- kumaneko san" msgstr "ccstools --- 熊猫さん" -#: ../src/menu.c:1123 +#: ../src/menu.c:1358 msgid "Yoshihiro Kusuno" msgstr "楠野 佳宏" -#: ../src/other.c:48 +#: ../src/other.c:49 msgid "Edit the selected line" msgstr "選択した行を修正します。" -#: ../src/other.c:224 +#: ../src/other.c:228 msgid "File Selection Dialog" msgstr "ファイルの選択" -#: ../src/other.c:264 +#: ../src/other.c:278 msgid "Manager Add" msgstr "マネージャを追加します。" -#: ../src/other.c:342 +#: ../src/other.c:358 #, c-format msgid "Delete the %d selected managers?" msgstr "選択した %d行のマネージャ登録を削除します。" -#: ../src/other.c:343 +#: ../src/other.c:359 #, c-format msgid "Delete the selected manager?" msgstr "選択したマネージャ登録を削除します。" -#: ../src/other.c:560 +#: ../src/other.c:598 msgid " " msgstr " " -#: ../src/other.c:567 +#: ../src/other.c:605 msgid "Now (bytes)" msgstr "使用量(バイト)" -#: ../src/other.c:577 +#: ../src/other.c:615 msgid "Quota (bytes)" msgstr "最大 (バイト)" -#: ../src/search.c:366 +#: ../src/search.c:424 msgid "Process Search for :" msgstr "プロセス 一覧 検索文字列 :" -#: ../src/search.c:368 +#: ../src/search.c:426 msgid "Domain Search for :" msgstr "ドメイン 一覧 検索文字列 :" -#: ../src/search.c:372 +#: ../src/search.c:430 msgid "ACL Search for :" msgstr "ドメインポリシー 一覧 検索文字列 :" -#: ../src/search.c:375 +#: ../src/search.c:433 msgid "Exception Search for :" msgstr "例外ポリシー 一覧 検索文字列 :" -#: ../src/search.c:378 +#: ../src/search.c:436 msgid "Profile Search for :" msgstr "プロファイル 一覧 検索文字列 :" -#: ../src/search.c:382 +#: ../src/search.c:440 msgid "Search for :" msgstr "検索文字列 :" -#: ../src/search.c:403 +#: ../src/search.c:475 +msgid "_Match case" +msgstr "大文字と小文字を区別する(_M)" + +#: ../src/search.c:481 +msgid "_Wrap around" +msgstr "折返しも対象にする(_W)" + +#: ../src/search.c:487 +msgid "Close _dialog" +msgstr "エンターで閉じる(_D)" + +#: ../src/search.c:516 msgid "Find" msgstr "検索" diff --git a/src/conf.c b/src/conf.c index 0911ec3..76aa4c3 100644 --- a/src/conf.c +++ b/src/conf.c @@ -29,14 +29,33 @@ #include #include "gpet.h" +#include "conf.h" #define PRINT_WARN(err) {g_warning("%s", err->message);g_error_free(err);err = NULL;} #define DIRECTORY "/apps/gpet" -#define WINDOW_POSITION DIRECTORY"/window_position" +#define WINDOW_POSITION DIRECTORY"/window_position" #define WINDOW_SIZE DIRECTORY"/window_size" -#define ACL_WINDOW_SIZE DIRECTORY"/acl_window_size" -#define PANED_POSITION DIRECTORY"/paned_position" +#define ACL_WINDOW_SIZE DIRECTORY"/acl_window_size" +#define PANED_POSITION DIRECTORY"/paned_position" + +#define SEARCH_DIR DIRECTORY"/search" +#define MATCH SEARCH_DIR"/match_case" +#define WRAP SEARCH_DIR"/wrap_around" +#define CLOSE SEARCH_DIR"/close_dialog" + + +static search_conf_t save_search = {TRUE, FALSE, FALSE}; + +void get_conf_search(search_conf_t *conf) +{ + *conf = save_search; +} + +void put_conf_search(search_conf_t *conf) +{ + save_search = *conf; +} void read_config(transition_t *tran) { @@ -45,6 +64,7 @@ void read_config(transition_t *tran) gint x, y, w, h; GtkPaned *paned; gint paned_position; + gboolean tmp_bool; gtk_widget_set_size_request(tran->window, 640, 480); gtk_widget_set_size_request(tran->acl_window, 600, 400); @@ -82,6 +102,29 @@ void read_config(transition_t *tran) else PRINT_WARN(err); } + + + if (!gconf_client_dir_exists(client, SEARCH_DIR, &err)) { + return; + } + + tmp_bool = gconf_client_get_bool(client, MATCH, &err); + if (!err) + save_search.match = tmp_bool; + else + PRINT_WARN(err); + + tmp_bool = gconf_client_get_bool(client, WRAP, &err); + if (!err) + save_search.wrap = tmp_bool; + else + PRINT_WARN(err); + + tmp_bool = gconf_client_get_bool(client, CLOSE, &err); + if (!err) + save_search.close = tmp_bool; + else + PRINT_WARN(err); } void write_config(transition_t *tran) @@ -128,5 +171,24 @@ void write_config(transition_t *tran) PRINT_WARN(err); } } + + + if (!gconf_client_dir_exists(client, SEARCH_DIR, &err)) { + gconf_client_add_dir(client, SEARCH_DIR, + GCONF_CLIENT_PRELOAD_NONE, &err); + } + if (err) { + PRINT_WARN(err); + return; + } + + if (!gconf_client_set_bool(client, MATCH, save_search.match, &err)) + PRINT_WARN(err); + + if (!gconf_client_set_bool(client, WRAP, save_search.wrap, &err)) + PRINT_WARN(err); + + if (!gconf_client_set_bool(client, CLOSE, save_search.close, &err)) + PRINT_WARN(err); } diff --git a/src/gpet b/src/gpet index f868f8b..961b072 100755 Binary files a/src/gpet and b/src/gpet differ diff --git a/src/gpet.c b/src/gpet.c index f4989f8..1632627 100644 --- a/src/gpet.c +++ b/src/gpet.c @@ -36,6 +36,42 @@ #include "gpet.h" /*---------------------------------------------------------------------------*/ +/* from util.c (ccs-patch-1.8.1-20110505) */ +static gboolean is_octal_char(const char *str) +{ + return *str >= '0' && *str++ <= '3' && + *str >= '0' && *str++ <= '7' && + *str >= '0' && *str <= '7'; +} +/* from util.c (ccs-patch-1.8.1-20110505) */ +static gchar octal_char_to_binary(const char *str) +{ + return ((str[0] - '0') << 6) + ((str[1] - '0') << 3) + (str[2] - '0'); +} + +gchar *decode_from_octal_str(const char *name) +{ + gchar *tmp, buff[strlen(name)+1]; + + if (!name) + return NULL; + + tmp = buff; + for( ; *name; name++, tmp++) { + if (*name == '\\' && is_octal_char(name + 1)) { + name++; + *tmp = octal_char_to_binary(name); + name += 2; + } else { + *tmp = *name; + } + } + *tmp = *name; + + return g_strdup(buff); +} + +/*---------------------------------------------------------------------------*/ enum tree_column_pos { COLUMN_INDEX, // data index (invisible) COLUMN_NUMBER, // n @@ -55,12 +91,14 @@ static int add_tree_store(GtkTreeStore *store, GtkTreeIter *parent_iter, { GtkTreeIter iter; gchar *color = "black"; - gchar *str_num, *str_prof; + gchar *str_num, *str_prof, *name; gchar *line = NULL, *is_dis = NULL, *domain; const char *sp; const struct ccs_transition_control_entry *transition_control; int n, number, redirect_index = -1; +//g_print("add_tree_store index[%3d] nest[%2d]\n", *index, nest); + sp = ccs_domain_name(dp, *index); for (n = 0; ; n++) { const char *cp = strchr(sp, ' '); @@ -68,6 +106,7 @@ static int add_tree_store(GtkTreeStore *store, GtkTreeIter *parent_iter, break; sp = cp + 1; } + name = decode_from_octal_str(sp); gtk_tree_store_append(store, &iter, parent_iter); number = dp->list[*index].number; @@ -120,7 +159,7 @@ static int add_tree_store(GtkTreeStore *store, GtkTreeIter *parent_iter, } domain = g_strdup_printf("%s%s%s%s%s", dp->list[*index].is_dd ? "( " : "", - sp, + name, dp->list[*index].is_dd ? " )" : "", line ? line : "", is_dis ? is_dis : "" @@ -128,6 +167,7 @@ static int add_tree_store(GtkTreeStore *store, GtkTreeIter *parent_iter, gtk_tree_store_set(store, &iter, COLUMN_DOMAIN_NAME, domain, COLUMN_COLOR, color, COLUMN_REDIRECT, redirect_index, -1); + g_free(name); g_free(line); g_free(is_dis); g_free(domain); @@ -159,7 +199,7 @@ void add_tree_data(GtkTreeView *treeview, struct ccs_domain_policy *dp) int index = 0, nest = -1; store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview)); - gtk_tree_store_clear(store); + gtk_tree_store_clear(store); // TODO 遅い add_tree_store(store, iter, dp, &index, nest); } /*---------------------------------------------------------------------------*/ @@ -284,14 +324,19 @@ void add_list_data(generic_list_t *generic, gboolean alias_flag) gtk_list_store_append(store, &iter); if (alias_flag) { + gchar *ope = decode_from_octal_str( + generic->list[i].operand); + alias = (gchar *) ccs_directives[generic->list[i].directive].alias; gtk_list_store_set(store, &iter, LIST_NUMBER, str_num, LIST_COLON, ":", LIST_ALIAS, alias, - LIST_OPERAND, generic->list[i].operand, +// LIST_OPERAND, generic->list[i].operand, + LIST_OPERAND, ope, // test -1); + g_free(ope); // test } else { profile = g_strdup_printf("%3u-", generic->list[i].directive); @@ -406,7 +451,7 @@ gint get_current_domain_index(transition_t *transition) return index; } -gchar *get_alias_and_operand(GtkWidget *view) +gchar *get_alias_and_operand(GtkWidget *view, gboolean alias_flag) { GtkTreeSelection *selection; GtkTreeIter iter; @@ -421,9 +466,17 @@ gchar *get_alias_and_operand(GtkWidget *view) list = gtk_tree_selection_get_selected_rows(selection, NULL); model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); gtk_tree_model_get_iter(model, &iter, g_list_first(list)->data); - gtk_tree_model_get(model, &iter, + if (alias_flag) { + gtk_tree_model_get(model, &iter, LIST_ALIAS, &alias, LIST_OPERAND, &operand, -1); - str_buff = g_strdup_printf("%s %s", alias, operand); + str_buff = g_strdup_printf("%s %s", alias, operand); + g_free(alias); + g_free(operand); + } else { + gtk_tree_model_get(model, &iter, + LIST_OPERAND, &operand, -1); + str_buff = g_strchug(operand); + } } return str_buff; @@ -434,10 +487,9 @@ static gboolean move_pos_list(GtkTreeModel *model, GtkTreePath *path, { GtkWidget *view = NULL; GtkTreeSelection *selection; - const char *domain; gint index; - gchar *alias = NULL, *operand = NULL, *str_buff = NULL; - gchar *entry; + gchar *alias = NULL, *operand = NULL; + gchar *entry, *str_buff = NULL; int cmp = -1; @@ -447,8 +499,9 @@ static gboolean move_pos_list(GtkTreeModel *model, GtkTreePath *path, case ADDENTRY_DOMAIN_LIST : view = transition->treeview; gtk_tree_model_get(model, iter, COLUMN_INDEX, &index, -1); - domain = ccs_domain_name(transition->dp, index); - cmp = strcmp(entry, domain); + str_buff = decode_from_octal_str( + ccs_domain_name(transition->dp, index)); + cmp = strcmp(entry, str_buff); break; case ADDENTRY_ACL_LIST : view = transition->acl.listview; @@ -475,6 +528,7 @@ static gboolean move_pos_list(GtkTreeModel *model, GtkTreePath *path, g_free(alias); g_free(operand); g_free(str_buff); + g_free(entry); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); @@ -545,13 +599,14 @@ void set_position_addentry(transition_t *transition, GtkTreePath **path) static void cb_selection(GtkTreeSelection *selection, transition_t *transition) { - GtkTreeIter iter; - gint select_count; - GtkTreeModel *model; - GList *list; - gint index; + GtkTreeIter iter; + gint select_count; + GtkTreeModel *model; + GList *list; + gint index; GtkTreePath *path = NULL; GtkTreeViewColumn *column = NULL; + gchar *name; DEBUG_PRINT("In **************************** \n"); select_count = gtk_tree_selection_count_selected_rows(selection); @@ -567,8 +622,9 @@ static void cb_selection(GtkTreeSelection *selection, g_list_free(list); gtk_tree_model_get(model, &iter, COLUMN_INDEX, &index, -1); DEBUG_PRINT("--- index [%4d] ---\n", index); - gtk_entry_set_text(GTK_ENTRY(transition->domainbar), - ccs_domain_name(transition->dp, index)); + name = decode_from_octal_str(ccs_domain_name(transition->dp, index)); + gtk_entry_set_text(GTK_ENTRY(transition->domainbar), name); + g_free(name); gtk_tree_view_get_cursor(GTK_TREE_VIEW( transition->acl.listview), &path, &column); @@ -735,6 +791,7 @@ void set_sensitive(GtkActionGroup *actions, int task_flag, case CCS_SCREEN_PROFILE_LIST : sens_edt = TRUE; sens_add = TRUE; + sens_cpy = TRUE; break; } @@ -1009,6 +1066,7 @@ g_free(str_path); gtk_tree_selection_unselect_path(selection, path); } + g_free(str_num); return FALSE; } diff --git a/src/gpet.h b/src/gpet.h index 7664206..ef638ba 100644 --- a/src/gpet.h +++ b/src/gpet.h @@ -129,10 +129,11 @@ const char *get_policy_dir(void); const char *get_domain_last_name(const int index); // gpet.c +gchar *decode_from_octal_str(const char *name); void add_tree_data(GtkTreeView *treeview, struct ccs_domain_policy *dp); void add_list_data(generic_list_t *generic, gboolean alias_flag); gint get_current_domain_index(transition_t *transition); -gchar *get_alias_and_operand(GtkWidget *view); +gchar *get_alias_and_operand(GtkWidget *view, gboolean alias_flag); void set_position_addentry(transition_t *transition, GtkTreePath **path); void set_sensitive(GtkActionGroup *actions, int task_flag, enum ccs_screen_type current_page); @@ -155,6 +156,7 @@ int gpet_main(void); GtkWidget *create_menu(GtkWidget *parent, transition_t *transition, GtkWidget **toolbar); void disp_statusbar(transition_t *transition, int scr); +gchar *encode_to_octal_str(const char *str); void view_cursor_set(GtkWidget *view, GtkTreePath *path, GtkTreeViewColumn *column); void refresh_transition(GtkAction *action, transition_t *transition); diff --git a/src/interface.inc b/src/interface.inc index 4cccb29..7433daa 100644 --- a/src/interface.inc +++ b/src/interface.inc @@ -94,6 +94,9 @@ static void generic_acl_copy(struct ccs_generic_acl **src, int src_cnt, while (dst_cnt) free((void *)((*dst)[--dst_cnt].operand)); + if (src_cnt < 1) + return; + *dst = realloc(*dst, src_cnt * sizeof(struct ccs_generic_acl)); if (!(*dst)) ccs_out_of_memory(); diff --git a/src/menu.c b/src/menu.c index 68ad844..3afc006 100644 --- a/src/menu.c +++ b/src/menu.c @@ -64,7 +64,7 @@ static GtkActionEntry entries[] = { N_("_OptimizationSupport"), "O", N_("Extraction of redundant ACL entries"), G_CALLBACK(optimize_acl)}, - {"Search", GTK_STOCK_FIND, N_("_Search"), "F", + {"Search", GTK_STOCK_FIND, N_("_Search..."), "F", N_("Search for text"), G_CALLBACK(search_input)}, {"SearchBack", GTK_STOCK_GO_BACK, N_("Search_Backwards"), "G", N_("Search backwards for the same text"), G_CALLBACK(search_back)}, @@ -73,9 +73,9 @@ static GtkActionEntry entries[] = { {"Refresh", GTK_STOCK_REFRESH, N_("_Refresh"), "R", N_("Refresh to the latest information"), G_CALLBACK(refresh_transition)}, - {"Manager", GTK_STOCK_DND, N_("_Manager"), "M", + {"Manager", GTK_STOCK_DND, N_("_Manager..."), "M", N_("Manager Profile Editor"), G_CALLBACK(manager_transition)}, - {"Memory", GTK_STOCK_DND, N_("_Statistics"), "S", + {"Memory", GTK_STOCK_DND, N_("_Statistics..."), "S", N_("Statistics"), G_CALLBACK(memory_transition)}, {"About", GTK_STOCK_ABOUT, N_("_About"), "A", @@ -256,6 +256,123 @@ void disp_statusbar(transition_t *transition, int scr) transition->contextid, status_str); g_free(status_str); } +/*---------------------------------------------------------------------------*/ +/* from realpath.c (ccs-patch-1.8.1-20110505) */ +gchar *encode_to_octal_str(const char *str) +{ + int i; + int str_len; + int len = 0; + const char *p = str; + char *cp; + char *cp0; + + if (!p) + return NULL; + + str_len = strlen(str); + for (i = 0; i < str_len; i++) { + const unsigned char c = p[i]; + if (c == '\\') +// len += 2; + len++; + else if (c > ' ' && c < 127) + len++; + else + len += 4; + } + len++; + + /* Reserve space for appending "/". */ + cp = g_malloc0(len + 10); + if (!cp) + return NULL; + + cp0 = cp; + p = str; + for (i = 0; i < str_len; i++) { + const unsigned char c = p[i]; + if (c == '\\') { + *cp++ = '\\'; +// *cp++ = '\\'; + } else if (c > ' ' && c < 127) { + *cp++ = c; + } else { + *cp++ = '\\'; + *cp++ = (c >> 6) + '0'; + *cp++ = ((c >> 3) & 7) + '0'; + *cp++ = (c & 7) + '0'; + } + } + return cp0; +} + +static gint encode_copy(gchar *cp, gchar *buff) +{ + gchar *str; + gint len; + + if (!*cp) + return 0; + + str = encode_to_octal_str(cp); + strcpy(buff, str); + len = strlen(str) - 1; + g_free(str); + + return len; +} + +static gchar *escape_str_encode(const char *input) +{ + gchar *str, *cp0, *cp1; + gchar *tmp, buff[strlen(input)*3+1]; + gboolean match = FALSE; + + if (!input) + return NULL; + + cp0 = str = g_strdup(input); + tmp = buff; + for( ; *cp0; cp0++, tmp++) { + if (*cp0 == '\\' && *(cp0 + 1) == '\'') { + *tmp = *++cp0; + } else if (*cp0 == '\'') { // start " + cp1 = ++cp0; + for ( ; *cp0; cp0++) { + if (*cp0 == '\\' && *(cp0 + 1) == '\'') { + if (cp1 < cp0) { + *cp0 = '\0'; + tmp += encode_copy(cp1, tmp); + tmp++; + } else { + *tmp = *(cp0 + 1); + } + cp1 = ++cp0; + } else if (*cp0 == '\'') { // end " + *cp0 = '\0'; + match = TRUE; + break; + } + } + + if (match) { + tmp += encode_copy(cp1, tmp); + match = FALSE; + } else { + g_warning(" [\']pair not match!"); + cp0 = cp1; + *tmp = *cp0; + } + } else { + *tmp = *cp0; + } + } + *tmp = *cp0; + + g_free(str); + return g_strdup(buff); +} /*-------+---------+---------+---------+---------+---------+---------+--------*/ static void terminate(GtkAction *action, transition_t *transition) { @@ -494,16 +611,20 @@ static void copy_line(GtkAction *action, transition_t *transition) index = get_current_domain_index(transition); view = transition->treeview; if (index >= 0) - insert_history_buffer(view, g_strdup( + insert_history_buffer(view, decode_from_octal_str( ccs_domain_name(transition->dp, index))); break; case CCS_SCREEN_ACL_LIST : view = transition->acl.listview; - insert_history_buffer(view, get_alias_and_operand(view)); + insert_history_buffer(view, get_alias_and_operand(view, TRUE)); break; case CCS_SCREEN_EXCEPTION_LIST : view = transition->exp.listview; - insert_history_buffer(view, get_alias_and_operand(view)); + insert_history_buffer(view, get_alias_and_operand(view, TRUE)); + break; + case CCS_SCREEN_PROFILE_LIST : + view = transition->prf.listview; + insert_history_buffer(view, get_alias_and_operand(view, FALSE)); break; default : break; @@ -693,7 +814,25 @@ static gchar *Last_entry_string = NULL; gchar *get_combo_entry_last(void) { - return Last_entry_string; + gchar *str, *buff; + gchar *cp; + + buff = g_malloc0(strlen(Last_entry_string) + 1); + if (!buff) + return NULL; + + str = buff; + for (cp = Last_entry_string; *cp; cp++) { + if (*cp == '\\' && *(cp + 1) == '\'') { + *str++ = *++cp; + } else if (*cp != '\'') { + *str++ = *cp; + } + } + *str = *cp; + +//g_print("[%s]\n", buff); + return buff; } static void insert_history_buffer(GtkWidget *view, gchar *entry) @@ -710,8 +849,10 @@ static void insert_history_buffer(GtkWidget *view, gchar *entry) gtk_clipboard_set_text(clipboard, entry, -1); for (list = combolist; list; list = g_list_next(list)) { - if (strcmp(entry, (gchar *)list->data) == 0) + if (strcmp(entry, (gchar *)list->data) == 0) { + g_free(entry); return; + } } combolist = g_list_insert(combolist, entry, 0); @@ -723,7 +864,59 @@ static void insert_history_buffer(GtkWidget *view, gchar *entry) } } -static gint combo_entry_activate(GtkWidget *combo, gchar **new_text) +static gchar *normalize_strdup(gchar *input) +{ + gchar *cp; + gint len = strlen(input); + gchar *str, *buff; + gboolean match = FALSE; + + if (len < 1) + return NULL; + + cp = input + len - 1; + if (g_ascii_isspace(*cp)) { + while (len && g_ascii_isspace(*cp)) { + cp--; + len--; + } + } + + cp = input; + while (len && g_ascii_isspace(*cp)) { + cp++; + len--; + } + + buff = g_malloc0(len + 1); + if (!buff) + return NULL; + + str = buff; + while (len && *cp) { + if (*cp == '\\' && *(cp + 1) == '\'') { + *str++ = *cp++; + len--; + } else if (*cp == '\'') { + match = match ? FALSE : TRUE; + } else { + if (!match && g_ascii_isspace(*cp)) { + while (g_ascii_isspace(*(cp+1))) { + cp++; + len--; + } + } + } + *str++ = *cp++; + len--; + } + *str = '\0'; + +//g_print("%2d[%s]\n", len, buff); + return buff; +} + +static gint combo_entry_apply(GtkWidget *combo, gchar **new_text) { GtkComboBox *combobox; GList *list; @@ -735,7 +928,9 @@ static gint combo_entry_activate(GtkWidget *combo, gchar **new_text) return 1; g_free(Last_entry_string); - Last_entry_string = g_strdup(*new_text); + Last_entry_string = normalize_strdup(*new_text); + g_free(*new_text); + *new_text = g_strdup(Last_entry_string); for (list = combolist; list; list = g_list_next(list)) { if (strcmp(*new_text, (gchar *)list->data) == 0) { @@ -757,6 +952,17 @@ static gint combo_entry_activate(GtkWidget *combo, gchar **new_text) return exist_flag ? 1 : 0; } +static void cb_combo_entry_activate(GtkEntry *entry, GtkWidget *dialog) +{ + const gchar *input = gtk_entry_get_text(entry); + + if (!input || strcmp(input, "") == 0) + return; + + gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY); +} + +/*---------------------------------------------------------------------------*/ static gint append_dialog(transition_t *transition, gchar *title, gchar **input) { @@ -777,6 +983,9 @@ static gint append_dialog(transition_t *transition, NULL); combo = gtk_combo_box_entry_new_text(); + g_signal_connect(G_OBJECT(GTK_BIN(combo)->child) , "activate" , + G_CALLBACK(cb_combo_entry_activate), dialog); + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); for (list = combolist; list; list = g_list_next(list)) { @@ -791,7 +1000,12 @@ static gint append_dialog(transition_t *transition, response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_APPLY) { - combo_entry_activate(combo, input); + gchar *tmp; + combo_entry_apply(combo, input); + tmp = escape_str_encode(*input); +// g_print("[%s]:[%s]\n", *input, tmp); + g_free(*input); + *input = tmp; result = 0; } gtk_widget_destroy(dialog); @@ -955,6 +1169,12 @@ static gboolean apply_profile(transition_t *transition, } } +static void cb_profile_activate(GtkTreeView *treeview, GtkTreePath *treepath, + GtkTreeViewColumn *treeviewcolumn, GtkWidget *dialog) +{ + gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY); +} + static void set_domain(transition_t *transition) { GtkTreeSelection *domain_selection; @@ -981,6 +1201,8 @@ static void set_domain(transition_t *transition) NULL); listview = create_list_profile(); + g_signal_connect(G_OBJECT(listview), "row-activated", + G_CALLBACK(cb_profile_activate), dialog); add_list_profile(listview, &(transition->prf)); view_cursor_set(listview, NULL, NULL); gtk_container_add( @@ -1004,6 +1226,16 @@ retry_profile: gtk_widget_destroy(dialog); } +static void cb_profile_entry_activate(GtkEntry *entry, GtkWidget *dialog) +{ + const gchar *input = gtk_entry_get_text(entry); + + if (!input || strcmp(input, "") == 0) + return; + + gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY); +} + static void edit_profile(transition_t *transition) { GtkWidget *dialog; @@ -1043,6 +1275,9 @@ static void edit_profile(transition_t *transition) GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, NULL); + g_signal_connect(G_OBJECT(entry) , "activate" , + G_CALLBACK(cb_profile_entry_activate), dialog); + hbox = gtk_hbox_new(FALSE, 5); gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); @@ -1133,8 +1368,8 @@ static void show_about_dialog(void) gtk_about_dialog_set_copyright(about, "Copyright(C) 2010,2011 TOMOYO Linux Project"); gtk_about_dialog_set_comments(about, - "Gui Policy Editor for TOMOYO Linux 1.8" - " or AKARI 1.0" + "Gui Policy Editor for TOMOYO Linux 1.8.1" + " or AKARI 1.0.11" "\n(based on ccs-editpolicy:ccstools)"); gtk_about_dialog_set_website(about, "http://sourceforge.jp/projects/gpet/"); // gtk_about_dialog_set_website_label(about, "http://tomoyo.sourceforge.jp/"); diff --git a/src/other.c b/src/other.c index 03fabb5..ada8f57 100644 --- a/src/other.c +++ b/src/other.c @@ -26,6 +26,7 @@ #include #include +#include #include "gpet.h" @@ -178,7 +179,8 @@ static void add_list_manager(generic_list_t *man) gtk_widget_grab_focus(man->listview); } -static void create_manager_view(GtkWidget *dialog, GtkWidget *listview) +static void create_manager_view(GtkWidget *dialog, GtkWidget *toolbar, + GtkWidget *listview) { GtkWidget *scrolledwin; @@ -189,6 +191,8 @@ static void create_manager_view(GtkWidget *dialog, GtkWidget *listview) GTK_SCROLLED_WINDOW(scrolledwin), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + toolbar, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwin, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(scrolledwin), listview); @@ -251,6 +255,16 @@ static void cb_button(GtkButton *button, gpointer data) gtk_widget_destroy(dialog); } +static void cb_manager_entry_activate(GtkEntry *entry, GtkWidget *dialog) +{ + const gchar *input = gtk_entry_get_text(entry); + + if (!input || strcmp(input, "") == 0) + return; + + gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY); +} + static void append_manager(GtkAction *action, other_t *data) { GtkWidget *dialog; @@ -273,6 +287,8 @@ static void append_manager(GtkAction *action, other_t *data) GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); entry = gtk_entry_new(); + g_signal_connect(G_OBJECT(entry) , "activate" , + G_CALLBACK(cb_manager_entry_activate), dialog); gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); g_object_set_data(G_OBJECT(entry), "parent", (gpointer)dialog); @@ -369,6 +385,7 @@ void manager_main(transition_t *transition) { other_t data; GtkWidget *dialog; + GtkWidget *toolbar; GtkWidget *listview; gchar *title; gint response; @@ -381,9 +398,9 @@ void manager_main(transition_t *transition) NULL); g_free(title); - create_dialog_menu(dialog, &data); + toolbar = create_dialog_menu(dialog, &data); listview = create_list_manager(); - create_manager_view(dialog, listview); + create_manager_view(dialog, toolbar, listview); data.dialog = dialog; data.manager.listview = listview; @@ -415,6 +432,25 @@ void manager_main(transition_t *transition) transition->current_page = CCS_SCREEN_DOMAIN_LIST; } /*-------+---------+---------+---------+---------+---------+---------+--------*/ +static void cnv_local_time(gchar *date, gchar *time) +{ + struct tm t, *lt; + time_t timet; + + memset(&t, 0, sizeof(t)); + sscanf(date, "%d/%d/%d", &(t.tm_year), &(t.tm_mon), &(t.tm_mday)); + sscanf(time, "%d:%d:%d", &(t.tm_hour), &(t.tm_min), &(t.tm_sec)); + + t.tm_year -= 1900; + t.tm_mon--; + timet = timegm(&t); + lt = localtime(&timet); + + g_sprintf(date, "%04d/%02d/%02d", + lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday); + g_sprintf(time, "%02d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec); +} + static void get_disp_column(const char *data, gchar **head, gchar **now_str, gchar **quota_str) { @@ -427,19 +463,19 @@ static void get_disp_column(const char *data, gchar **head, memset(name, 0, sizeof(name)); memset(date, 0, sizeof(date)); memset(time, 0, sizeof(time)); - if ((cnt = sscanf(data, "Policy update: %u %s %s %s", + if ((cnt = sscanf(data, "Policy update: %u (%s %s %s)", &now, name, date, time)) >= 1) { *head = "Policy update"; } else if ((cnt = sscanf(data, - "Policy violation in learning mode: %u %s %s %s", + "Policy violation in learning mode: %u (%s %s %s)", &now, name, date, time)) >= 1) { *head = "Policy violation in learning mode"; } else if ((cnt = sscanf(data, - "Policy violation in permissive mode: %u %s %s %s", + "Policy violation in permissive mode: %u (%s %s %s)", &now, name, date, time)) >= 1) { *head = "Policy violation in permissive mode"; } else if ((cnt = sscanf(data, - "Policy violation in enforcing mode: %u %s %s %s", + "Policy violation in enforcing mode: %u (%s %s %s)", &now, name, date, time)) >= 1) { *head = "Policy violation in enforcing mode"; } else if ((cnt = sscanf(data, @@ -467,10 +503,12 @@ static void get_disp_column(const char *data, gchar **head, bQuota = FALSE; *now_str = bNow ? g_strdup_printf("%u", now) : g_strdup(""); - if (strlen(name)) + if (strlen(name)) { + cnv_local_time(date, time); *quota_str = g_strdup_printf("%s %s %s", name, date, time); - else + } else { *quota_str = bQuota ? g_strdup_printf("%u", quota) : g_strdup(""); + } } enum mem_column_pos { @@ -584,7 +622,8 @@ static GtkWidget *create_list_memory(generic_list_t *mem) return treeview; } -static void create_memory_view(GtkWidget *dialog, GtkWidget *listview) +static void create_memory_view(GtkWidget *dialog, GtkWidget *toolbar, + GtkWidget *listview) { GtkWidget *scrolledwin; @@ -595,6 +634,8 @@ static void create_memory_view(GtkWidget *dialog, GtkWidget *listview) GTK_SCROLLED_WINDOW(scrolledwin), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), + toolbar, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwin, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(scrolledwin), listview); @@ -623,6 +664,7 @@ void memory_main(transition_t *transition) { other_t data; GtkWidget *dialog; + GtkWidget *toolbar; GtkWidget *listview; gchar *title; gint response; @@ -631,18 +673,19 @@ void memory_main(transition_t *transition) dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(transition->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); g_free(title); data.dialog = dialog; data.memory.count = 0; data.memory.list = NULL; - create_dialog_menu(dialog, &data); + toolbar = create_dialog_menu(dialog, &data); listview = create_list_memory(&(data.memory)); data.memory.listview = listview; - create_memory_view(dialog, listview); + create_memory_view(dialog, toolbar, listview); add_list_memory(&(data.memory)); @@ -655,8 +698,9 @@ void memory_main(transition_t *transition) gtk_widget_set_name(dialog, "GpetStatisticsDialog"); // .gpetrc gtk_widget_show_all(dialog); +retry_memory: response = gtk_dialog_run(GTK_DIALOG(dialog)); - if (response == GTK_RESPONSE_APPLY) { + if (response == GTK_RESPONSE_APPLY || response == GTK_RESPONSE_OK) { char *err_buff = NULL; DEBUG_PRINT("Apply button was pressed.\n"); if (set_memory(data.memory.list, @@ -664,6 +708,11 @@ void memory_main(transition_t *transition) g_warning("%s", err_buff); free(err_buff); } + + if (response == GTK_RESPONSE_APPLY) { + add_list_memory(&(data.memory)); + goto retry_memory; + } } else { DEBUG_PRINT("Another response was recieved.\n"); } diff --git a/src/process.c b/src/process.c index 805116c..3dfb04e 100644 --- a/src/process.c +++ b/src/process.c @@ -30,11 +30,11 @@ #include "gpet.h" enum task_column_pos { - COLUMN_INDEX, // data index (invisible) + COLUMN_INDEX, // data index (invisible) COLUMN_NUMBER, // n - COLUMN_COLON, // : + COLUMN_COLON, // : COLUMN_PROFILE, // profile - COLUMN_NAME, // process name + pid + domain name + COLUMN_NAME, // process name + pid + domain name N_COLUMNS_TREE }; @@ -45,6 +45,7 @@ static int add_task_tree_store(GtkTreeStore *store, { GtkTreeIter iter; gchar *str_prof; + gchar *str_domain; gchar *line; int n = 0, index; @@ -52,18 +53,20 @@ static int add_task_tree_store(GtkTreeStore *store, index = tsk->task[*number].index; str_prof = g_strdup_printf("%3u", tsk->task[*number].profile); + str_domain = decode_from_octal_str(tsk->task[*number].domain); line = g_strdup_printf("%s (%u) %s", tsk->task[*number].name, tsk->task[*number].pid, - tsk->task[*number].domain); + str_domain); gtk_tree_store_set(store, &iter, COLUMN_INDEX, index, COLUMN_NUMBER, *number, COLUMN_COLON, ":", - COLUMN_PROFILE, str_prof, + COLUMN_PROFILE, str_prof, COLUMN_NAME, line, -1); DEBUG_PRINT("[%3d]%3d(%d):%s %s\n", index, *number, nest, str_prof, line); + g_free(str_domain); g_free(str_prof); g_free(line); @@ -148,11 +151,12 @@ static gboolean cb_select_process(GtkTreeView *treeview, static void cb_selection_proc(GtkTreeSelection *selection, transition_t *transition) { - GtkTreeIter iter; - gint select_count; - GtkTreeModel *model; - GList *list; - gint index; + GtkTreeIter iter; + gint select_count; + GtkTreeModel *model; + GList *list; + gint index; + gchar *str_domain; GtkTreePath *path = NULL; GtkTreeViewColumn *column = NULL; @@ -167,8 +171,10 @@ static void cb_selection_proc(GtkTreeSelection *selection, g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); g_list_free(list); gtk_tree_model_get(model, &iter, COLUMN_INDEX, &index, -1); - gtk_entry_set_text(GTK_ENTRY(transition->domainbar), - transition->tsk.task[index].domain); + + str_domain = decode_from_octal_str(transition->tsk.task[index].domain); + gtk_entry_set_text(GTK_ENTRY(transition->domainbar), str_domain); + g_free(str_domain); gtk_tree_view_get_cursor(GTK_TREE_VIEW( transition->acl.listview), &path, &column); diff --git a/src/search.c b/src/search.c index ca1cf70..253f3a3 100644 --- a/src/search.c +++ b/src/search.c @@ -28,10 +28,12 @@ #include #include "gpet.h" +#include "conf.h" typedef struct _search_t { transition_t *tran; GtkWidget *combo; + GtkWidget *dialog; } search_t; #define COMBO_LIST_LIMIT 10 @@ -217,14 +219,42 @@ static gint get_current_index(transition_t *transition) static void search(transition_t *transition, gboolean forward) { GtkWidget *view = NULL; - gint index, count; + gint index, start_index, count; gchar *str_p = NULL; + gchar *haystack = NULL; + gchar *tmp_entry, *entry = NULL; + search_conf_t conf; - index = get_current_index(transition); + if (!S_entry || strcmp(S_entry, "") == 0) + return; + + get_conf_search(&conf); + + tmp_entry = encode_to_octal_str(S_entry); + entry = conf.match ? g_strdup(tmp_entry) : g_ascii_strup(tmp_entry, -1); + g_free(tmp_entry); + + start_index = index = get_current_index(transition); count = get_list_count(transition); - while (S_entry) { - forward ? index++ : index--; - if (index < 0 || count <= index) + while (entry) { + if (forward) { + index++; + if (count <= index) { + if (conf.wrap) + index = 0; + else + break; + } + } else { + index--; + if (index < 0) { + if (conf.wrap) + index = count - 1; + else + break; + } + } + if (index == start_index) break; switch((int)transition->current_page) { @@ -263,18 +293,25 @@ static void search(transition_t *transition, gboolean forward) break; } - if(g_strrstr(str_p, S_entry)) { + g_free(haystack); + haystack = conf.match ? + g_strdup(str_p) : g_ascii_strup(str_p, -1); + + if (transition->current_page != CCS_SCREEN_DOMAIN_LIST) + g_free(str_p); + + if(g_strrstr(haystack, entry)) { GtkTreeModel *model; put_locate_index(transition, index); model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc)search_pos_list, transition); + g_free(haystack); break; } } - if (transition->current_page != CCS_SCREEN_DOMAIN_LIST) - g_free(str_p); + g_free(entry); gtk_action_set_sensitive(gtk_action_group_get_action( transition->actions, "SearchBack"), TRUE); @@ -298,7 +335,7 @@ static void cb_combo_changed(GtkComboBox *combobox, gpointer nothing) } } -static void cb_combo_entry_activate(GtkEntry *entry, search_t *srch) +static void cb_search_entry_activate(GtkEntry *entry, search_t *srch) { GtkComboBox *combobox; gchar *new_text; @@ -307,12 +344,13 @@ static void cb_combo_entry_activate(GtkEntry *entry, search_t *srch) combobox = GTK_COMBO_BOX(srch->combo); new_text = gtk_combo_box_get_active_text(combobox); - if(!new_text || strcmp(new_text, "") == 0) + if (!new_text || strcmp(new_text, "") == 0) { return; + } g_free(S_entry); S_entry = g_strdup(new_text); -// g_print("cb_combo_entry_activate[%s]\n", new_text); +// g_print("cb_search_entry_activate[%s]\n", new_text); for (list = combolist; list; list = g_list_next(list)) { if (strcmp(new_text, (gchar *)list->data) == 0) { @@ -330,20 +368,36 @@ static void cb_combo_entry_activate(GtkEntry *entry, search_t *srch) } } - if (entry) + if (entry) { + search_conf_t conf; search(srch->tran, TRUE); + get_conf_search(&conf); + if (conf.close) + gtk_dialog_response(GTK_DIALOG(srch->dialog), + GTK_RESPONSE_CLOSE); + } } static void cb_btn_prev_clicked(GtkButton *widget , search_t *srch) { - cb_combo_entry_activate(NULL, srch); + search_conf_t conf; + cb_search_entry_activate(NULL, srch); search(srch->tran, FALSE); + get_conf_search(&conf); + if (conf.close) + gtk_dialog_response(GTK_DIALOG(srch->dialog), + GTK_RESPONSE_CLOSE); } static void cb_btn_next_clicked(GtkButton *widget , search_t *srch) { - cb_combo_entry_activate(NULL, srch); + search_conf_t conf; + cb_search_entry_activate(NULL, srch); search(srch->tran, TRUE); + get_conf_search(&conf); + if (conf.close) + gtk_dialog_response(GTK_DIALOG(srch->dialog), + GTK_RESPONSE_CLOSE); } /*-------+---------+---------+---------+---------+---------+---------+--------*/ GList *insert_item(GtkComboBox *combobox, @@ -389,6 +443,60 @@ static gchar *search_title(transition_t *transition) return title; } +static void cb_toggled_match(GtkToggleButton *widget, search_conf_t *conf) +{ + conf->match = gtk_toggle_button_get_active(widget); + put_conf_search(conf); +} +static void cb_toggled_wrap(GtkToggleButton *widget, search_conf_t *conf) +{ + conf->wrap = gtk_toggle_button_get_active(widget); + put_conf_search(conf); +} +static void cb_toggled_close(GtkToggleButton *widget, search_conf_t *conf) +{ + conf->close = gtk_toggle_button_get_active(widget); + put_conf_search(conf); +} + +static void create_check_box(GtkWidget *parent, search_conf_t *conf) +{ + GtkWidget *hbox, *vbox_l, *vbox_r; + GtkWidget *match, *wrap, *close; + + hbox = gtk_hbox_new(FALSE, 15); + gtk_box_pack_start(GTK_BOX(parent), hbox, TRUE, TRUE, 10); + + vbox_l = gtk_vbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox), vbox_l, TRUE, FALSE, 0); + vbox_r = gtk_vbox_new(FALSE, 5); + gtk_box_pack_start(GTK_BOX(hbox), vbox_r, TRUE, FALSE, 0); + + match = gtk_check_button_new_with_mnemonic(_("_Match case")); + gtk_box_pack_start(GTK_BOX(vbox_l), match, TRUE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(match), conf->match); + g_signal_connect(G_OBJECT(match), "toggled", + G_CALLBACK(cb_toggled_match), conf); + + wrap = gtk_check_button_new_with_mnemonic(_("_Wrap around")); + gtk_box_pack_start(GTK_BOX(vbox_l), wrap, TRUE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wrap), conf->wrap); + g_signal_connect(G_OBJECT(wrap), "toggled", + G_CALLBACK(cb_toggled_wrap), conf); + + close = gtk_check_button_new_with_mnemonic(_("Close _dialog")); + gtk_box_pack_start(GTK_BOX(vbox_r), close, FALSE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(close), conf->close); + g_signal_connect(G_OBJECT(close), "toggled", + G_CALLBACK(cb_toggled_close), conf); + +/* + 大文字と小文字を区別する (M)atch case + 折返しも対象にする (W)rap around + enterで閉じる Close (d)ialog +*/ +} + void search_input(GtkAction *action, transition_t *transition) { GtkWidget *dialog, *parent; @@ -398,6 +506,7 @@ void search_input(GtkAction *action, transition_t *transition) GtkWidget *btn_next, *btn_prev; GList *list; search_t srch; + search_conf_t conf; gint response; parent = (transition->acl_detached && @@ -425,10 +534,11 @@ void search_input(GtkAction *action, transition_t *transition) entry = gtk_combo_box_entry_new_text(); srch.tran = transition; srch.combo = entry; + srch.dialog = dialog; g_signal_connect(G_OBJECT(entry) , "changed", G_CALLBACK(cb_combo_changed), NULL); g_signal_connect(G_OBJECT(GTK_BIN(entry)->child) , "activate" , - G_CALLBACK(cb_combo_entry_activate), &srch); + G_CALLBACK(cb_search_entry_activate), &srch); gtk_box_pack_start(GTK_BOX(vbox_l), entry, FALSE, FALSE, 0); for (list = combolist; list; list = g_list_next(list)) { @@ -437,20 +547,23 @@ void search_input(GtkAction *action, transition_t *transition) } gtk_combo_box_set_active(GTK_COMBO_BOX(entry), 0); + get_conf_search(&conf); + create_check_box(vbox_l, &conf); + vbox_r = gtk_vbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox), vbox_r, FALSE, FALSE, 0); btn_prev = gtk_button_new_from_stock(GTK_STOCK_GO_BACK); - gtk_box_pack_start(GTK_BOX(vbox_r), btn_prev, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox_r), btn_prev, TRUE, TRUE, 0); g_signal_connect(G_OBJECT(btn_prev) , "clicked" , G_CALLBACK (cb_btn_prev_clicked) , &srch); btn_next = gtk_button_new_from_stock(GTK_STOCK_GO_FORWARD); - gtk_box_pack_start(GTK_BOX(vbox_r), btn_next, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox_r), btn_next, TRUE, TRUE, 0); g_signal_connect(G_OBJECT(btn_next) , "clicked" , G_CALLBACK (cb_btn_next_clicked) , &srch); - gtk_widget_set_size_request(dialog, 400, -1); + gtk_widget_set_size_request(dialog, 520, -1); put_locate_index(transition, get_current_index(transition)); gtk_widget_show_all(dialog);