xaizek / vide (License: GPLv2+) (since 2018-12-07)
Graphical predecessor of vifm that uses GTK+.
<root> / src / size_filter_dialog.c (5bac97ad77548e757ae3a57bc8e396f55c55fc48) (5,369B) (mode 100644) [raw]
/* vide
 * Copyright (C) 2000 Ken Steen.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "vide.h"

static GtkWidget *dialog;
static GtkWidget *operation_combo;
static GtkWidget *size_entry;
static GtkWidget *units_combo;

static void
ok_cb (GtkWidget * widget, FileView * view)
{
  gchar *s;
  double size;

  view->size_filter.active = TRUE;
  //set_filter_menu_active (view);

  s = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (operation_combo)->entry));
  if (STREQ (s, "Bigger Than"))
    view->size_filter.op = GT;
  else
    view->size_filter.op = LT;

  s = gtk_entry_get_text (GTK_ENTRY (size_entry));
  size = atof (s);

  s = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (units_combo)->entry));
  if (STREQ (s, "Bytes"))
    view->size_filter.size = (off_t) size;
  else if (STREQ (s, "KBytes"))
    view->size_filter.size = (off_t) (size * (1 << 10));
  else
    view->size_filter.size = (off_t) (size * (1 << 20));

  gtk_grab_remove (dialog);
  gtk_widget_destroy (dialog);
  load_dir_list (view);
}

static void
cancel_cb (GtkWidget * widget)
{
  gtk_grab_remove (dialog);
  gtk_widget_destroy (dialog);
}

static void
key_press_cb (GtkWidget * widget, GdkEventKey * event, gpointer data)
{
  if (event->keyval == GDK_Escape)
    cancel_cb (NULL);
}

void
create_size_filter_dialog (FileView * view)
{
  GtkWidget *dialog_vbox;
  GtkWidget *action_area;
  GtkWidget *hbox;
  gchar size_string[32];
  GList *tmp = NULL;

  dialog = gtk_dialog_new ();
  dialog_vbox = GTK_DIALOG (dialog)->vbox;
  action_area = GTK_DIALOG (dialog)->action_area;
  gtk_container_set_border_width (GTK_CONTAINER (dialog_vbox), 5);
  gtk_box_set_spacing (GTK_BOX (dialog_vbox), 5);
  gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
		      GTK_SIGNAL_FUNC (key_press_cb), NULL);

  add_label (dialog_vbox, "Size Filter: ", 0.0, FALSE, 5);

  hbox = add_hbox (dialog_vbox, FALSE, 5, TRUE, 5);

  operation_combo = gtk_combo_new ();
  gtk_widget_set_usize (operation_combo, 110, 0);
  gtk_box_pack_start (GTK_BOX (hbox), operation_combo, FALSE, FALSE, 0);
  gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (operation_combo)->entry),
			  FALSE);
  gtk_widget_show (operation_combo);

  tmp = g_list_append (tmp, strdup ("Bigger Than"));
  tmp = g_list_append (tmp, strdup ("Smaller Than"));
  gtk_combo_set_popdown_strings (GTK_COMBO (operation_combo), tmp);
  g_list_free (tmp);
  tmp = NULL;

  switch (view->size_filter.op)
    {
    case GT:
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (operation_combo)->entry),
			  "Bigger Than");
      break;
    case LT:
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (operation_combo)->entry),
			  "Smaller Than");
      break;
    default:
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (operation_combo)->entry),
			  "Bigger Than");
      break;
    }

  size_entry = add_entry (hbox, "", FALSE, 0);
  gtk_widget_set_usize (size_entry, 60, 0);

  units_combo = gtk_combo_new ();
  gtk_widget_set_usize (units_combo, 80, 0);
  gtk_box_pack_start (GTK_BOX (hbox), units_combo, FALSE, FALSE, 0);
  gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (units_combo)->entry), FALSE);
  gtk_widget_show (units_combo);

  tmp = g_list_append (tmp, strdup ("Bytes"));
  tmp = g_list_append (tmp, strdup ("KBytes"));
  tmp = g_list_append (tmp, strdup ("MBytes"));
  gtk_combo_set_popdown_strings (GTK_COMBO (units_combo), tmp);
  g_list_free (tmp);
  tmp = NULL;

  if (view->size_filter.size < (1 << 10))
    {
      g_snprintf (size_string, sizeof (size_string), "%ld",
		  view->size_filter.size);
      gtk_entry_set_text (GTK_ENTRY (size_entry), size_string);
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (units_combo)->entry),
			  "Bytes");
    }
  else if (view->size_filter.size < (1 << 20))
    {
      g_snprintf (size_string, sizeof (size_string), "%.2f",
		  (double) ((double) view->size_filter.size /
			    (double) (1 << 10)));
      gtk_entry_set_text (GTK_ENTRY (size_entry), size_string);
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (units_combo)->entry),
			  "KBytes");
    }
  else
    {
      g_snprintf (size_string, sizeof (size_string), "%.2f",
		  (double) ((double) view->size_filter.size /
			    (double) (1 << 20)));
      gtk_entry_set_text (GTK_ENTRY (size_entry), size_string);
      gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (units_combo)->entry),
			  "MBytes");
    }

  add_button (action_area, "Ok", FALSE, 0, ok_cb, view);
  add_button (action_area, "Cancel", FALSE, 0, cancel_cb, NULL);

  gtk_widget_show (dialog);
  gtk_grab_add (dialog);
  gtk_window_set_transient_for (GTK_WINDOW (dialog),
				GTK_WINDOW (app.main_window));
}
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vide

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vide

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master