Merge remote-tracking branch 'carrotIndustries/develop' into develop

This commit is contained in:
Sebastian Ramacher 2015-12-09 00:30:32 +01:00
commit 14af953708
8 changed files with 75 additions and 31 deletions

View file

@ -440,11 +440,12 @@ cb_password_dialog(GtkEntry* entry, zathura_password_dialog_info_t* dialog)
} }
/* try to open document again */ /* try to open document again */
if (document_open(dialog->zathura, dialog->path, input, if (document_open(dialog->zathura, dialog->path, dialog->uri, input,
ZATHURA_PAGE_NUMBER_UNSPECIFIED) == false) { ZATHURA_PAGE_NUMBER_UNSPECIFIED) == false) {
gdk_threads_add_idle(password_dialog, dialog); gdk_threads_add_idle(password_dialog, dialog);
} else { } else {
g_free(dialog->path); g_free(dialog->path);
g_free(dialog->uri);
free(dialog); free(dialog);
} }

View file

@ -22,6 +22,7 @@
*/ */
struct zathura_document_s { struct zathura_document_s {
char* file_path; /**< File path of the document */ char* file_path; /**< File path of the document */
char* uri; /**< URI of the document */
char* basename; /**< Basename of the document */ char* basename; /**< Basename of the document */
const char* password; /**< Password of the document */ const char* password; /**< Password of the document */
unsigned int current_page_number; /**< Current page number */ unsigned int current_page_number; /**< Current page number */
@ -61,7 +62,7 @@ check_set_error(zathura_error_t* error, zathura_error_t code) {
zathura_document_t* zathura_document_t*
zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char* zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char*
path, const char* password, zathura_error_t* error) path, const char *uri, const char* password, zathura_error_t* error)
{ {
if (path == NULL) { if (path == NULL) {
return NULL; return NULL;
@ -115,7 +116,15 @@ zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char*
} }
document->file_path = real_path; document->file_path = real_path;
document->basename = g_file_get_basename(file); document->uri = g_strdup(uri);
if (document->uri == NULL) {
document->basename = g_file_get_basename(file);
}
else {
GFile *gf = g_file_new_for_uri(document->uri);
document->basename = g_file_get_basename(gf);
g_object_unref(gf);
}
document->password = password; document->password = password;
document->scale = 1.0; document->scale = 1.0;
document->plugin = plugin; document->plugin = plugin;
@ -216,9 +225,8 @@ zathura_document_free(zathura_document_t* document)
error = functions->document_free(document, document->data); error = functions->document_free(document, document->data);
} }
if (document->file_path != NULL) { g_free(document->file_path);
free(document->file_path); g_free(document->uri);
}
g_free(document->basename); g_free(document->basename);
g_free(document); g_free(document);
@ -236,6 +244,16 @@ zathura_document_get_path(zathura_document_t* document)
return document->file_path; return document->file_path;
} }
const char*
zathura_document_get_uri(zathura_document_t* document)
{
if (document == NULL) {
return NULL;
}
return document->uri;
}
const char* const char*
zathura_document_get_basename(zathura_document_t* document) zathura_document_get_basename(zathura_document_t* document)
{ {

View file

@ -18,7 +18,7 @@
* @return The document object and NULL if an error occurs * @return The document object and NULL if an error occurs
*/ */
zathura_document_t* zathura_document_open(zathura_plugin_manager_t* zathura_document_t* zathura_document_open(zathura_plugin_manager_t*
plugin_manager, const char* path, const char* password, zathura_error_t* plugin_manager, const char* path, const char *uri, const char* password, zathura_error_t*
error); error);
/** /**
@ -38,6 +38,14 @@ zathura_error_t zathura_document_free(zathura_document_t* document);
*/ */
const char* zathura_document_get_path(zathura_document_t* document); const char* zathura_document_get_path(zathura_document_t* document);
/**
* Returns the URI of the document
*
* @param document The document
* @return The URI of the document
*/
const char* zathura_document_get_uri(zathura_document_t* document);
/** /**
* Returns the basename of the document * Returns the basename of the document
* *

View file

@ -12,6 +12,7 @@
typedef struct zathura_password_dialog_info_s typedef struct zathura_password_dialog_info_s
{ {
char* path; /**< Path to the file */ char* path; /**< Path to the file */
char* uri; /**< URI to the file */
zathura_t* zathura; /**< Zathura session */ zathura_t* zathura; /**< Zathura session */
} zathura_password_dialog_info_t; } zathura_password_dialog_info_t;

View file

@ -78,12 +78,10 @@ cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
return; return;
} }
const char* file_path = zathura_document_get_path(zathura->document); char* file_path = get_formatted_filename(zathura, true);
girara_statusbar_item_set_text(zathura->ui.session,
if (file_path != NULL) { zathura->ui.statusbar.file, file_path);
girara_statusbar_item_set_text(zathura->ui.session, g_free(file_path);
zathura->ui.statusbar.file, file_path);
}
} }
static void static void

View file

@ -442,7 +442,7 @@ sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
document_close(zathura, true); document_close(zathura, true);
/* reopen document */ /* reopen document */
document_open(zathura, zathura->file_monitor.file_path, document_open(zathura, zathura->file_monitor.file_path, NULL,
zathura->file_monitor.password, zathura->file_monitor.password,
ZATHURA_PAGE_NUMBER_UNSPECIFIED); ZATHURA_PAGE_NUMBER_UNSPECIFIED);

View file

@ -566,6 +566,7 @@ document_info_open(gpointer data)
{ {
zathura_document_info_t* document_info = data; zathura_document_info_t* document_info = data;
g_return_val_if_fail(document_info != NULL, FALSE); g_return_val_if_fail(document_info != NULL, FALSE);
char* uri = NULL;
if (document_info->zathura != NULL && document_info->path != NULL) { if (document_info->zathura != NULL && document_info->path != NULL) {
char* file = NULL; char* file = NULL;
@ -586,6 +587,7 @@ document_info_open(gpointer data)
} }
else { else {
/* copy file with GIO */ /* copy file with GIO */
uri = g_file_get_uri(gf);
file = prepare_document_open_from_gfile(gf); file = prepare_document_open_from_gfile(gf);
if (file == NULL) { if (file == NULL) {
girara_notify(document_info->zathura->ui.session, GIRARA_ERROR, girara_notify(document_info->zathura->ui.session, GIRARA_ERROR,
@ -599,13 +601,14 @@ document_info_open(gpointer data)
if (file != NULL) { if (file != NULL) {
if (document_info->synctex != NULL) { if (document_info->synctex != NULL) {
document_open_synctex(document_info->zathura, file, document_open_synctex(document_info->zathura, file, uri,
document_info->password, document_info->synctex); document_info->password, document_info->synctex);
} else { } else {
document_open(document_info->zathura, file, document_info->password, document_open(document_info->zathura, file, uri, document_info->password,
document_info->page_number); document_info->page_number);
} }
g_free(file); g_free(file);
g_free(uri);
if (document_info->mode != NULL) { if (document_info->mode != NULL) {
if (g_strcmp0(document_info->mode, "presentation") == 0) { if (g_strcmp0(document_info->mode, "presentation") == 0) {
@ -625,14 +628,18 @@ document_info_open(gpointer data)
return FALSE; return FALSE;
} }
static char* char*
get_formatted_filename(zathura_t* zathura, const char* file_path, bool statusbar) get_formatted_filename(zathura_t* zathura, bool statusbar)
{ {
bool basename_only = false; bool basename_only = false;
const char* file_path = zathura_document_get_uri(zathura->document);
if (file_path == NULL) {
file_path = zathura_document_get_path(zathura->document);
}
if (statusbar == true) { if (statusbar == true) {
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
} else {
girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only); girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only);
} else {
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
} }
if (basename_only == false) { if (basename_only == false) {
@ -679,7 +686,7 @@ document_open_password_dialog(gpointer data)
} }
bool bool
document_open(zathura_t* zathura, const char* path, const char* password, document_open(zathura_t* zathura, const char* path, const char* uri, const char* password,
int page_number) int page_number)
{ {
if (zathura == NULL || zathura->plugins.manager == NULL || path == NULL) { if (zathura == NULL || zathura->plugins.manager == NULL || path == NULL) {
@ -688,7 +695,7 @@ document_open(zathura_t* zathura, const char* path, const char* password,
gchar* file_uri = NULL; gchar* file_uri = NULL;
zathura_error_t error = ZATHURA_ERROR_OK; zathura_error_t error = ZATHURA_ERROR_OK;
zathura_document_t* document = zathura_document_open(zathura->plugins.manager, path, password, &error); zathura_document_t* document = zathura_document_open(zathura->plugins.manager, path, uri, password, &error);
if (document == NULL) { if (document == NULL) {
if (error == ZATHURA_ERROR_INVALID_PASSWORD) { if (error == ZATHURA_ERROR_INVALID_PASSWORD) {
@ -697,6 +704,7 @@ document_open(zathura_t* zathura, const char* path, const char* password,
if (password_dialog_info != NULL) { if (password_dialog_info != NULL) {
password_dialog_info->zathura = zathura; password_dialog_info->zathura = zathura;
password_dialog_info->path = g_strdup(path); password_dialog_info->path = g_strdup(path);
password_dialog_info->uri = g_strdup(uri);
if (password_dialog_info->path != NULL) { if (password_dialog_info->path != NULL) {
gdk_threads_add_idle(document_open_password_dialog, password_dialog_info); gdk_threads_add_idle(document_open_password_dialog, password_dialog_info);
@ -712,6 +720,8 @@ document_open(zathura_t* zathura, const char* path, const char* password,
} }
goto error_out; goto error_out;
} }
zathura->document = document;
const char* file_path = zathura_document_get_path(document); const char* file_path = zathura_document_get_path(document);
unsigned int number_of_pages = zathura_document_get_number_of_pages(document); unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
@ -797,7 +807,7 @@ document_open(zathura_t* zathura, const char* path, const char* password,
zathura->bisect.end = number_of_pages - 1; zathura->bisect.end = number_of_pages - 1;
/* update statusbar */ /* update statusbar */
char* filename = get_formatted_filename(zathura, file_path, true); char* filename = get_formatted_filename(zathura, true);
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, filename); girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, filename);
g_free(filename); g_free(filename);
@ -843,8 +853,6 @@ document_open(zathura_t* zathura, const char* path, const char* password,
goto error_free; goto error_free;
} }
zathura->document = document;
/* page cache size */ /* page cache size */
int cache_size = 0; int cache_size = 0;
girara_setting_get(zathura->ui.session, "page-cache-size", &cache_size); girara_setting_get(zathura->ui.session, "page-cache-size", &cache_size);
@ -973,7 +981,7 @@ document_open(zathura_t* zathura, const char* path, const char* password,
} }
/* update title */ /* update title */
char* formatted_filename = get_formatted_filename(zathura, file_path, false); char* formatted_filename = get_formatted_filename(zathura, false);
girara_set_window_title(zathura->ui.session, formatted_filename); girara_set_window_title(zathura->ui.session, formatted_filename);
g_free(formatted_filename); g_free(formatted_filename);
@ -1026,10 +1034,10 @@ error_out:
} }
bool bool
document_open_synctex(zathura_t* zathura, const char* path, document_open_synctex(zathura_t* zathura, const char* path, const char* uri,
const char* password, const char* synctex) const char* password, const char* synctex)
{ {
bool ret = document_open(zathura, path, password, bool ret = document_open(zathura, path, password, uri,
ZATHURA_PAGE_NUMBER_UNSPECIFIED); ZATHURA_PAGE_NUMBER_UNSPECIFIED);
if (ret == false) { if (ret == false) {
return false; return false;
@ -1261,7 +1269,7 @@ statusbar_page_number_update(zathura_t* zathura)
girara_setting_get(zathura->ui.session, "window-title-page", &page_number_in_window_title); girara_setting_get(zathura->ui.session, "window-title-page", &page_number_in_window_title);
if (page_number_in_window_title == true) { if (page_number_in_window_title == true) {
char* filename = get_formatted_filename(zathura, zathura_document_get_path(zathura->document), false); char* filename = get_formatted_filename(zathura, false);
char* title = g_strdup_printf("%s %s", filename, page_number_text); char* title = g_strdup_printf("%s %s", filename, page_number_text);
girara_set_window_title(zathura->ui.session, title); girara_set_window_title(zathura->ui.session, title);
g_free(title); g_free(title);

View file

@ -306,7 +306,7 @@ void zathura_set_argv(zathura_t* zathura, char** argv);
* *
* @return If no error occured true, otherwise false, is returned. * @return If no error occured true, otherwise false, is returned.
*/ */
bool document_open(zathura_t* zathura, const char* path, const char* password, bool document_open(zathura_t* zathura, const char* path, const char* uri, const char* password,
int page_number); int page_number);
/** /**
@ -319,7 +319,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* password,
* *
* @return If no error occured true, otherwise false, is returned. * @return If no error occured true, otherwise false, is returned.
*/ */
bool document_open_synctex(zathura_t* zathura, const char* path, bool document_open_synctex(zathura_t* zathura, const char* path, const char* uri,
const char* password, const char* synctex); const char* password, const char* synctex);
/** /**
@ -470,4 +470,14 @@ void zathura_jumplist_trim(zathura_t* zathura);
*/ */
bool zathura_jumplist_load(zathura_t* zathura, const char* file); bool zathura_jumplist_load(zathura_t* zathura, const char* file);
/**
* Gets the nicely formatted filename of the loaded document according to settings
*
* @param zathura The zathura session
* @param statusbar Whether return value will be dispalyed in status bar
*
* return Printable filename. Free with g_free.
*/
char* get_formatted_filename(zathura_t* zathura, bool statusbar);
#endif // ZATHURA_H #endif // ZATHURA_H