rofi  1.7.0
filebrowser.c File Reference
#include <errno.h>
#include <gio/gio.h>
#include <gmodule.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "dialogs/filebrowser.h"
#include "helper.h"
#include "history.h"
#include "mode-private.h"
#include "mode.h"
#include "rofi.h"
#include "theme.h"
#include <stdint.h>
#include "rofi-icon-fetcher.h"
Include dependency graph for filebrowser.c:

Go to the source code of this file.

Data Structures

struct  FBFile
 
struct  FileBrowserModePrivateData
 

Macros

#define FILEBROWSER_CACHE_FILE   "rofi3.filebrowsercache"
 

Enumerations

enum  FBFileType { UP , DIRECTORY , RFILE , NUM_FILE_TYPES }
 
enum  FBSortingMethod { FB_SORT_NAME , FB_SORT_TIME }
 
enum  FBSortingTime { FB_MTIME , FB_ATIME , FB_CTIME }
 

Functions

static void free_list (FileBrowserModePrivateData *pd)
 
static gint compare_name (gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data)
 
static gint compare_time (gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpointer data)
 
static gint compare (gconstpointer a, gconstpointer b, gpointer data)
 
static time_t get_time (const struct stat *statbuf)
 
static void set_time (FBFile *file)
 
static void get_file_browser (Mode *sw)
 
static void file_browser_mode_init_config (Mode *sw)
 
static void file_browser_mode_init_current_dir (Mode *sw)
 
static int file_browser_mode_init (Mode *sw)
 
static unsigned int file_browser_mode_get_num_entries (const Mode *sw)
 
static ModeMode file_browser_mode_result (Mode *sw, int mretv, char **input, unsigned int selected_line)
 
static void file_browser_mode_destroy (Mode *sw)
 
static char * _get_display_value (const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry)
 
static int file_browser_token_match (const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
 
static cairo_surface_t * _get_icon (const Mode *sw, unsigned int selected_line, int height)
 
static char * _get_message (const Mode *sw)
 
static char * _get_completion (const Mode *sw, unsigned int index)
 
Modecreate_new_file_browser (void)
 
ModeMode file_browser_mode_completer (Mode *sw, int mretv, char **input, unsigned int selected_line, char **path)
 

Variables

const char * icon_name [NUM_FILE_TYPES] = {"go-up", "folder", "gtk-file"}
 
struct {
   enum FBSortingMethod   sorting_method
 
   enum FBSortingTime   sorting_time
 
   gboolean   directories_first
 
file_browser_config
 
Mode file_browser_mode
 

Macro Definition Documentation

◆ FILEBROWSER_CACHE_FILE

#define FILEBROWSER_CACHE_FILE   "rofi3.filebrowsercache"

rofi-file_browser

MIT/X11 License Copyright (c) 2017 Qball Cow qball.nosp@m.@gmp.nosp@m.clien.nosp@m.t.or.nosp@m.g

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition at line 50 of file filebrowser.c.

Enumeration Type Documentation

◆ FBFileType

enum FBFileType

The internal data structure holding the private data of the TEST Mode.

Enumerator
UP 
DIRECTORY 
RFILE 
NUM_FILE_TYPES 

Definition at line 55 of file filebrowser.c.

◆ FBSortingMethod

Possible sorting methods

Enumerator
FB_SORT_NAME 
FB_SORT_TIME 

Definition at line 65 of file filebrowser.c.

◆ FBSortingTime

Type of time to sort by

Enumerator
FB_MTIME 
FB_ATIME 
FB_CTIME 

Definition at line 73 of file filebrowser.c.

Function Documentation

◆ _get_completion()

static char* _get_completion ( const Mode sw,
unsigned int  index 
)
static

Definition at line 552 of file filebrowser.c.

References FileBrowserModePrivateData::array, mode_get_private_data(), and FBFile::path.

Here is the call graph for this function:

◆ _get_display_value()

static char* _get_display_value ( const Mode sw,
unsigned int  selected_line,
G_GNUC_UNUSED int *  state,
G_GNUC_UNUSED GList **  attr_list,
int  get_entry 
)
static

Definition at line 484 of file filebrowser.c.

References FileBrowserModePrivateData::array, FBFile::link, mode_get_private_data(), FBFile::name, FBFile::type, and UP.

Here is the call graph for this function:

◆ _get_icon()

static cairo_surface_t* _get_icon ( const Mode sw,
unsigned int  selected_line,
int  height 
)
static

◆ _get_message()

static char* _get_message ( const Mode sw)
static

Definition at line 539 of file filebrowser.c.

References FileBrowserModePrivateData::current_dir, and mode_get_private_data().

Here is the call graph for this function:

◆ compare()

static gint compare ( gconstpointer  a,
gconstpointer  b,
gpointer  data 
)
static

Definition at line 157 of file filebrowser.c.

References compare_name(), compare_time(), FB_SORT_NAME, FB_SORT_TIME, and file_browser_config.

Referenced by get_file_browser().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_name()

static gint compare_name ( gconstpointer  a,
gconstpointer  b,
G_GNUC_UNUSED gpointer  data 
)
static

Definition at line 125 of file filebrowser.c.

References file_browser_config, FBFile::name, and FBFile::type.

Referenced by compare().

Here is the caller graph for this function:

◆ compare_time()

static gint compare_time ( gconstpointer  a,
gconstpointer  b,
G_GNUC_UNUSED gpointer  data 
)
static

Definition at line 137 of file filebrowser.c.

References file_browser_config, FBFile::time, and FBFile::type.

Referenced by compare().

Here is the caller graph for this function:

◆ file_browser_mode_destroy()

static void file_browser_mode_destroy ( Mode sw)
static

Definition at line 473 of file filebrowser.c.

References FileBrowserModePrivateData::current_dir, free_list(), mode_get_private_data(), and mode_set_private_data().

Here is the call graph for this function:

◆ file_browser_mode_get_num_entries()

static unsigned int file_browser_mode_get_num_entries ( const Mode sw)
static

Definition at line 396 of file filebrowser.c.

References FileBrowserModePrivateData::array_length, and mode_get_private_data().

Here is the call graph for this function:

◆ file_browser_mode_init()

static int file_browser_mode_init ( Mode sw)
static

Called on startup when enabled (in modi list)

Definition at line 380 of file filebrowser.c.

References file_browser_mode_init_config(), file_browser_mode_init_current_dir(), get_file_browser(), mode_get_private_data(), and mode_set_private_data().

Here is the call graph for this function:

◆ file_browser_mode_init_config()

static void file_browser_mode_init_config ( Mode sw)
static

◆ file_browser_mode_init_current_dir()

static void file_browser_mode_init_current_dir ( Mode sw)
static

Definition at line 345 of file filebrowser.c.

References cache_dir, FileBrowserModePrivateData::current_dir, FILEBROWSER_CACHE_FILE, mode_get_private_data(), rofi_mode::name, P_STRING, rofi_config_find_widget(), rofi_theme_find_property(), _PropertyValue::s, Property::type, and Property::value.

Referenced by file_browser_mode_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_browser_mode_result()

◆ file_browser_token_match()

static int file_browser_token_match ( const Mode sw,
rofi_int_matcher **  tokens,
unsigned int  index 
)
static
Parameters
swThe mode object.
tokensThe tokens to match against.
indexThe index in this plugin to match against.

Match the entry.

Returns
try when a match.

Definition at line 513 of file filebrowser.c.

References FileBrowserModePrivateData::array, helper_token_match(), mode_get_private_data(), and FBFile::name.

Here is the call graph for this function:

◆ free_list()

static void free_list ( FileBrowserModePrivateData pd)
static

◆ get_file_browser()

static void get_file_browser ( Mode sw)
static

Get the entries to display. this gets called on plugin initialization.

Definition at line 202 of file filebrowser.c.

References FileBrowserModePrivateData::array, FileBrowserModePrivateData::array_length, compare(), FileBrowserModePrivateData::current_dir, DIRECTORY, FB_SORT_TIME, file_browser_config, get_time(), FBFile::icon_fetch_uid, FBFile::link, mode_get_private_data(), FBFile::name, FBFile::path, RFILE, set_time(), FBFile::time, FBFile::type, and UP.

Referenced by file_browser_mode_completer(), file_browser_mode_init(), and file_browser_mode_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_time()

static time_t get_time ( const struct stat *  statbuf)
static

Definition at line 175 of file filebrowser.c.

References FB_ATIME, FB_CTIME, FB_MTIME, and file_browser_config.

Referenced by get_file_browser(), and set_time().

Here is the caller graph for this function:

◆ set_time()

static void set_time ( FBFile file)
static

Definition at line 188 of file filebrowser.c.

References get_time(), FBFile::path, and FBFile::time.

Referenced by get_file_browser().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ directories_first

gboolean directories_first

If we want to display directories above files.

Definition at line 105 of file filebrowser.c.

◆ 

struct { ... } file_browser_config
Initial value:
= {
.sorting_method = FB_SORT_NAME,
.sorting_time = FB_MTIME,
.directories_first = TRUE,
}
@ FB_SORT_NAME
Definition: filebrowser.c:66
@ FB_MTIME
Definition: filebrowser.c:74

The sorting settings used in file-browser.

Referenced by compare(), compare_name(), compare_time(), file_browser_mode_init_config(), get_file_browser(), and get_time().

◆ icon_name

const char* icon_name[NUM_FILE_TYPES] = {"go-up", "folder", "gtk-file"}

Icons to use for the file type

Definition at line 80 of file filebrowser.c.

Referenced by _get_icon().

◆ sorting_method

enum FBSortingMethod sorting_method

Field to sort on.

Definition at line 93 of file filebrowser.c.

◆ sorting_time

enum FBSortingTime sorting_time

If sorting on time, what time entry.

Definition at line 93 of file filebrowser.c.