mirror of
https://github.com/jtheoof/swappy.git
synced 2024-09-11 14:55:49 +03:00
feat(cli): add configure options for filename save
This commit is contained in:
parent
a931acb2cf
commit
597f0055b9
@ -43,6 +43,7 @@ The following lines can be used as swappy's default:
|
||||
```
|
||||
[Default]
|
||||
save_dir=$HOME/Desktop
|
||||
save_filename_format=swappy-%Y%m%d-%H%M%S.png
|
||||
show_panel=false
|
||||
line_size=5
|
||||
text_size=20
|
||||
@ -50,6 +51,7 @@ text_font=sans-serif
|
||||
```
|
||||
|
||||
- `save_dir` is where swappshots will be saved, can contain env variables and must exist in your filesystem
|
||||
- `save_filename_format`: is the filename template, if it contains a date format, this will be parsed into a timestamp. Format is detailed in [strftime(3)](https://linux.die.net/man/3/strftime). If this date format is missing, filename will have no timestamp
|
||||
- `show_panel` is used to toggle the paint panel on or off upon startup
|
||||
- `line_size` is the default line size (must be between 1 and 50)
|
||||
- `text_size` is the default text size (must be between 10 and 50)
|
||||
|
@ -4,6 +4,7 @@
|
||||
#define CONFIG_TEXT_FONT_DEFAULT "sans-serif"
|
||||
#define CONFIG_TEXT_SIZE_DEFAULT 20
|
||||
#define CONFIG_SHOW_PANEL_DEFAULT false
|
||||
#define CONFIG_SAVE_FILENAME_FORMAT_DEFAULT "swappy-%Y%m%d_%H%M%S.png"
|
||||
|
||||
void config_load(struct swappy_state *state);
|
||||
void config_free(struct swappy_state *state);
|
@ -3,6 +3,7 @@
|
||||
#include "swappy.h"
|
||||
|
||||
GdkPixbuf *pixbuf_get_from_state(struct swappy_state *state);
|
||||
void pixbuf_save_state_to_folder(GdkPixbuf *pixbuf, char *folder);
|
||||
void pixbuf_save_state_to_folder(GdkPixbuf *pixbuf, char *folder,
|
||||
char *filename_format);
|
||||
void pixbuf_save_to_file(GdkPixbuf *pixbuf, char *file);
|
||||
void pixbuf_save_to_stdout(GdkPixbuf *pixbuf);
|
@ -135,6 +135,7 @@ struct swappy_state_ui {
|
||||
struct swappy_config {
|
||||
char *config_file;
|
||||
char *save_dir;
|
||||
char *save_filename_format;
|
||||
gboolean show_panel;
|
||||
guint32 line_size;
|
||||
guint32 text_size;
|
||||
|
@ -184,7 +184,8 @@ static void save_state_to_file_or_folder(struct swappy_state *state,
|
||||
GdkPixbuf *pixbuf = pixbuf_get_from_state(state);
|
||||
|
||||
if (file == NULL) {
|
||||
pixbuf_save_state_to_folder(pixbuf, state->config->save_dir);
|
||||
pixbuf_save_state_to_folder(pixbuf, state->config->save_dir,
|
||||
state->config->save_filename_format);
|
||||
} else {
|
||||
pixbuf_save_to_file(pixbuf, file);
|
||||
}
|
||||
|
15
src/config.c
15
src/config.c
@ -14,6 +14,7 @@ static void print_config(struct swappy_config *config) {
|
||||
g_info("printing config:");
|
||||
g_info("config_dir: %s", config->config_file);
|
||||
g_info("save_dir: %s", config->save_dir);
|
||||
g_info("save_filename_format: %s", config->save_filename_format);
|
||||
g_info("show_panel: %d", config->show_panel);
|
||||
g_info("line_size: %d", config->line_size);
|
||||
g_info("text_font: %s", config->text_font);
|
||||
@ -69,6 +70,7 @@ static void load_config_from_file(struct swappy_config *config,
|
||||
GKeyFile *gkf;
|
||||
const gchar *group = "Default";
|
||||
gchar *save_dir = NULL;
|
||||
gchar *save_filename_format = NULL;
|
||||
gboolean show_panel;
|
||||
gchar *save_dir_expanded = NULL;
|
||||
guint64 line_size, text_size;
|
||||
@ -108,6 +110,17 @@ static void load_config_from_file(struct swappy_config *config,
|
||||
error = NULL;
|
||||
}
|
||||
|
||||
save_filename_format =
|
||||
g_key_file_get_string(gkf, group, "save_filename_format", &error);
|
||||
|
||||
if (error == NULL) {
|
||||
config->save_filename_format = save_filename_format;
|
||||
} else {
|
||||
g_info("save_filename_format is missing in %s (%s)", file, error->message);
|
||||
g_error_free(error);
|
||||
error = NULL;
|
||||
}
|
||||
|
||||
line_size = g_key_file_get_uint64(gkf, group, "line_size", &error);
|
||||
|
||||
if (error == NULL) {
|
||||
@ -172,6 +185,7 @@ static void load_default_config(struct swappy_config *config) {
|
||||
}
|
||||
|
||||
config->save_dir = get_default_save_dir();
|
||||
config->save_filename_format = g_strdup(CONFIG_SAVE_FILENAME_FORMAT_DEFAULT);
|
||||
config->line_size = CONFIG_LINE_SIZE_DEFAULT;
|
||||
config->text_font = g_strdup(CONFIG_TEXT_FONT_DEFAULT);
|
||||
config->text_size = CONFIG_TEXT_SIZE_DEFAULT;
|
||||
@ -200,6 +214,7 @@ void config_free(struct swappy_state *state) {
|
||||
if (state->config) {
|
||||
g_free(state->config->config_file);
|
||||
g_free(state->config->save_dir);
|
||||
g_free(state->config->save_filename_format);
|
||||
g_free(state->config->text_font);
|
||||
g_free(state->config);
|
||||
state->config = NULL;
|
||||
|
13
src/pixbuf.c
13
src/pixbuf.c
@ -31,17 +31,18 @@ static void write_file(GdkPixbuf *pixbuf, char *path) {
|
||||
g_free(message);
|
||||
}
|
||||
|
||||
void pixbuf_save_state_to_folder(GdkPixbuf *pixbuf, char *folder) {
|
||||
time_t current_time;
|
||||
void pixbuf_save_state_to_folder(GdkPixbuf *pixbuf, char *folder,
|
||||
char *filename_format) {
|
||||
time_t current_time = time(NULL);
|
||||
char *c_time_string;
|
||||
|
||||
time(¤t_time);
|
||||
char filename[strlen(filename_format) + 3];
|
||||
|
||||
c_time_string = ctime(¤t_time);
|
||||
c_time_string[strlen(c_time_string) - 1] = '\0';
|
||||
strftime(filename, sizeof(filename), filename_format,
|
||||
localtime(¤t_time));
|
||||
char path[MAX_PATH];
|
||||
g_snprintf(path, MAX_PATH, "%s/%s %s.png", folder, "Swappshot",
|
||||
c_time_string);
|
||||
g_snprintf(path, MAX_PATH, "%s/%s", folder, filename);
|
||||
write_file(pixbuf, path);
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ The following lines can be used as swappy's default:
|
||||
```
|
||||
[Default]
|
||||
save_dir=$HOME/Desktop
|
||||
save_filename_format=swappy-%Y%m%d-%H%M%S.png
|
||||
show_panel=false
|
||||
line_size=5
|
||||
text_size=20
|
||||
@ -65,6 +66,7 @@ The following lines can be used as swappy's default:
|
||||
```
|
||||
|
||||
- *save_dir* is where swappshots will be saved, can contain env variables and must exist in your filesystem
|
||||
- *save_filename_format* is the filename template, if it contains a date format, this will be parsed into a timestamp. Format is detailed in strftime(3). If this date format is missing, filename will have no timestamp
|
||||
- *show_panel* is used to toggle the paint panel on or off upon startup
|
||||
- *line_size* is the default line size (must be between 1 and 50)
|
||||
- *text_size* is the default text size (must be between 10 and 50)
|
||||
|
Loading…
Reference in New Issue
Block a user