Skip to content

Commit

Permalink
Disable sorting feature
Browse files Browse the repository at this point in the history
As GtkTreeView is broken and will not be fixed, I need to disable
this feature that is causing more harm than good to the final users.
Sorting by colum will come back with v3.0, because GtkTreeView
will be replaced by GtkColumnView
  • Loading branch information
paolostivanin committed Mar 30, 2021
1 parent 61329d4 commit 580d893
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 148 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(OTPClient VERSION "2.4.3" LANGUAGES "C")
project(OTPClient VERSION "2.4.4" LANGUAGES "C")

configure_file("src/common/version.h.in" "version.h")
include_directories(${PROJECT_BINARY_DIR})
Expand Down
8 changes: 8 additions & 0 deletions data/com.github.paolostivanin.OTPClient.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ It's also possible to import/export backups from/to andOTP and import backups fr
</content_rating>

<releases>
<release version="2.4.4" date="2021-03-30">
<description>
<p>OTPClient 2.4.4 disabled a broken feature</p>
<ul>
<li>remove possibility to sort columns by either account or issuer due to GtkTreeView issues. This feature will come back with 3.0.0</li>
</ul>
</description>
</release>
<release version="2.4.3" date="2021-03-25">
<description>
<p>OTPClient 2.4.3 contains some small fixes</p>
Expand Down
3 changes: 1 addition & 2 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ set_action_group (GtkBuilder *builder,
{ .name = "change_pwd", .activate = change_password_cb },
{ .name = "edit_row", .activate = edit_selected_row_cb },
{ .name = "settings", .activate = settings_dialog_cb },
{ .name = "shortcuts", .activate = shortcuts_window_cb },
{ .name = "reset_sort", .activate = reset_column_sorting_cb }
{ .name = "shortcuts", .activate = shortcuts_window_cb }
};

static GActionEntry add_menu_entries[] = {
Expand Down
100 changes: 0 additions & 100 deletions src/treeview.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ static gboolean clear_all_otps (GtkTreeModel *model,

static void free_pjd (ParsedData *pjd);

static void get_sort_data (gint *column_id, GtkSortType *sort_order);


void
create_treeview (AppData *app_data)
Expand All @@ -53,13 +51,6 @@ create_treeview (AppData *app_data)

gtk_tree_view_set_model (app_data->tree_view, GTK_TREE_MODEL(list_store));

gint column_id = -1;
GtkSortType sort_order = -1;
get_sort_data (&column_id, &sort_order);
if (column_id >= 0 && sort_order >= 0) {
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(list_store), column_id, sort_order);
}

// model has id 0 for type, 1 for label, 2 for issuer, etc while ui file has 0 label and 1 issuer. That's why the "+1"
gtk_tree_view_set_search_column (GTK_TREE_VIEW(app_data->tree_view), app_data->search_column + 1);

Expand Down Expand Up @@ -173,61 +164,6 @@ row_selected_cb (GtkTreeView *tree_view,
}


void
reset_column_sorting_cb (GSimpleAction *simple __attribute__((unused)),
GVariant *parameter __attribute__((unused)),
gpointer user_data)
{
AppData *app_data = (AppData *)user_data;
GError *err = NULL;
gchar *err_msg;
GKeyFile *kf = g_key_file_new ();
gchar *cfg_file_path;
#ifndef USE_FLATPAK_APP_FOLDER
cfg_file_path = g_build_filename (g_get_user_config_dir (), "otpclient.cfg", NULL);
#else
cfg_file_path = g_build_filename (g_get_user_data_dir (), "otpclient.cfg", NULL);
#endif
if (g_file_test (cfg_file_path, G_FILE_TEST_EXISTS)) {
if (!g_key_file_load_from_file (kf, cfg_file_path, G_KEY_FILE_NONE, &err)) {
g_printerr ("%s\n", err->message);
} else {
if (g_key_file_has_key (kf, "config", "column_id", NULL)) {
if (!g_key_file_remove_key (kf, "config", "column_id", &err) && err != NULL) {
err_msg = g_strconcat ("Couldn't reset the column id: ", err->message, NULL);
show_message_dialog (app_data->main_window, err_msg, GTK_MESSAGE_ERROR);
g_free (err_msg);
g_clear_error (&err);
}
}
if (g_key_file_has_key (kf, "config", "sort_order", NULL)) {
if (!g_key_file_remove_key (kf, "config", "sort_order", &err) && err != NULL) {
err_msg = g_strconcat ("Couldn't reset the sorting order: ", err->message, NULL);
show_message_dialog (app_data->main_window, err_msg, GTK_MESSAGE_ERROR);
g_free (err_msg);
g_clear_error (&err);
}
}
if (!g_key_file_save_to_file (kf, cfg_file_path, &err) && err != NULL) {
err_msg = g_strconcat ("Couldn't save the configuration file: ", err->message, NULL);
show_message_dialog (app_data->main_window, err_msg, GTK_MESSAGE_ERROR);
g_free (err_msg);
g_clear_error (&err);
}
}
}
g_key_file_free (kf);
g_free (cfg_file_path);

// set default sorting value
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(GTK_LIST_STORE(gtk_tree_view_get_model (app_data->tree_view))), -2, 0);

update_model (app_data);

show_message_dialog (app_data->main_window, "Sorting order has been correctly reset.", GTK_MESSAGE_INFO);
}


static void
hide_all_otps_cb (GtkTreeView *tree_view,
gpointer user_data)
Expand Down Expand Up @@ -316,13 +252,11 @@ add_columns (GtkTreeView *tree_view)
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Account", renderer, "text", COLUMN_ACC_LABEL, NULL);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN(column), GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN(column), 1); // 1 is the account column
gtk_tree_view_append_column (tree_view, column);

renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Issuer", renderer, "text", COLUMN_ACC_ISSUER, NULL);
gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN(column), GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_sort_column_id (GTK_TREE_VIEW_COLUMN(column), 2); // 2 is the issuer column
gtk_tree_view_append_column (tree_view, column);

renderer = gtk_cell_renderer_text_new ();
Expand Down Expand Up @@ -366,37 +300,3 @@ free_pjd (ParsedData *pjd)
g_array_free (pjd->periods, TRUE);
g_free (pjd);
}


static void
get_sort_data (gint *column_id,
GtkSortType *sort_order)
{
GError *err = NULL;
GKeyFile *kf = g_key_file_new ();
gchar *cfg_file_path;
#ifndef USE_FLATPAK_APP_FOLDER
cfg_file_path = g_build_filename (g_get_user_config_dir (), "otpclient.cfg", NULL);
#else
cfg_file_path = g_build_filename (g_get_user_data_dir (), "otpclient.cfg", NULL);
#endif
if (g_file_test (cfg_file_path, G_FILE_TEST_EXISTS)) {
if (!g_key_file_load_from_file (kf, cfg_file_path, G_KEY_FILE_NONE, &err)) {
g_printerr ("%s\n", err->message);
} else {
*column_id = g_key_file_get_integer (kf, "config", "column_id", &err);
if (err != NULL && (err->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND || err->code == G_KEY_FILE_ERROR_INVALID_VALUE)) {
*column_id = -1;
*sort_order = -1;
} else {
*sort_order = g_key_file_get_integer (kf, "config", "sort_order", &err);
if (err != NULL && (err->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND || err->code == G_KEY_FILE_ERROR_INVALID_VALUE)) {
*column_id = -1;
*sort_order = -1;
}
}
}
}
g_key_file_free (kf);
g_free (cfg_file_path);
}
4 changes: 0 additions & 4 deletions src/treeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ void row_selected_cb (GtkTreeView *tree_view,
GtkTreeViewColumn *column,
gpointer user_data);

void reset_column_sorting_cb (GSimpleAction *simple ,
GVariant *parameter,
gpointer user_data);

G_END_DECLS
41 changes: 0 additions & 41 deletions src/ui/otpclient.ui
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2
Copyright (C) 2020
This file is part of OTPClient.
OTPClient is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OTPClient is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OTPClient. If not, see <http://www.gnu.org/licenses/>.
Author: Paolo Stivanin
-->
<interface>
<requires lib="gtk+" version="3.18"/>
<!-- interface-license-type gplv3 -->
<!-- interface-name OTPClient -->
<!-- interface-description Highly secure and easy to use GTK+ OTP client -->
<!-- interface-copyright 2019 -->
<!-- interface-authors Paolo Stivanin -->
<object class="GtkPopoverMenu" id="add_pop_id">
<property name="can_focus">False</property>
<child>
Expand Down Expand Up @@ -1644,20 +1617,6 @@ Please note that &lt;b&gt;there is no way to recover a forgotten password.&lt;/b
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkModelButton" id="resetsort_model_btn_id">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">settings_menu.reset_sort</property>
<property name="text" translatable="yes">Reset column sorting</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
</object>
<packing>
<property name="submenu">main</property>
Expand Down

0 comments on commit 580d893

Please sign in to comment.