Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
370deafb
Commit
370deafb
authored
Apr 20, 2012
by
Moritz Lipp
Browse files
Save pages-per-row/position_x/position_y in database
parent
66999860
Changes
4
Show whitespace changes
Inline
Side-by-side
database-plain.c
View file @
370deafb
...
...
@@ -20,6 +20,9 @@
#define KEY_OFFSET "offset"
#define KEY_SCALE "scale"
#define KEY_ROTATE "rotate"
#define KEY_PAGES_PER_ROW "pages-per-row"
#define KEY_POSITION_X "position-x"
#define KEY_POSITION_Y "position-y"
#ifdef __GNU__
#include <sys/file.h>
...
...
@@ -375,17 +378,28 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
return
false
;
}
char
*
tmp
=
g_strdup_printf
(
"%f"
,
file_info
->
scale
);
char
*
name
=
prepare_filename
(
file
);
g_key_file_set_integer
(
priv
->
history
,
name
,
KEY_PAGE
,
file_info
->
current_page
);
g_key_file_set_integer
(
priv
->
history
,
name
,
KEY_OFFSET
,
file_info
->
page_offset
);
char
*
tmp
=
g_strdup_printf
(
"%f"
,
file_info
->
scale
);
g_key_file_set_string
(
priv
->
history
,
name
,
KEY_SCALE
,
tmp
);
g_free
(
tmp
);
g_key_file_set_integer
(
priv
->
history
,
name
,
KEY_ROTATE
,
file_info
->
rotation
);
g_key_file_set_integer
(
priv
->
history
,
name
,
KEY_PAGES_PER_ROW
,
file_info
->
pages_per_row
);
g_free
(
name
);
tmp
=
g_strdup_printf
(
"%f"
,
file_info
->
position_x
);
g_key_file_set_string
(
priv
->
history
,
name
,
KEY_POSITION_X
,
tmp
);
g_free
(
tmp
);
tmp
=
g_strdup_printf
(
"%f"
,
file_info
->
position_y
);
g_key_file_set_string
(
priv
->
history
,
name
,
KEY_POSITION_Y
,
tmp
);
g_free
(
tmp
);
g_free
(
name
);
zathura_db_write_key_file_to_file
(
priv
->
history_path
,
priv
->
history
);
return
true
;
...
...
@@ -412,10 +426,20 @@ plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info
->
current_page
=
g_key_file_get_integer
(
priv
->
history
,
name
,
KEY_PAGE
,
NULL
);
file_info
->
page_offset
=
g_key_file_get_integer
(
priv
->
history
,
name
,
KEY_OFFSET
,
NULL
);
file_info
->
rotation
=
g_key_file_get_integer
(
priv
->
history
,
name
,
KEY_ROTATE
,
NULL
);
file_info
->
pages_per_row
=
g_key_file_get_integer
(
priv
->
history
,
name
,
KEY_PAGES_PER_ROW
,
NULL
);
char
*
scale_string
=
g_key_file_get_string
(
priv
->
history
,
name
,
KEY_SCALE
,
NULL
);
file_info
->
scale
=
strtod
(
scale_string
,
NULL
);
g_free
(
scale_string
);
char
*
position_x_string
=
g_key_file_get_string
(
priv
->
history
,
name
,
KEY_POSITION_X
,
NULL
);
file_info
->
position_x
=
strtod
(
position_x_string
,
NULL
);
g_free
(
position_x_string
);
char
*
position_y_string
=
g_key_file_get_string
(
priv
->
history
,
name
,
KEY_POSITION_Y
,
NULL
);
file_info
->
position_y
=
strtod
(
position_y_string
,
NULL
);
g_free
(
position_y_string
);
g_free
(
name
);
return
true
;
...
...
database-sqlite.c
View file @
370deafb
...
...
@@ -118,7 +118,11 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
"page INTEGER,"
"offset INTEGER,"
"scale FLOAT,"
"rotation INTEGER);"
;
"rotation INTEGER,"
"pages_per_row INTEGER,"
"position_x FLOAT,"
"position_y FLOAT"
");"
;
sqlite3
*
session
=
NULL
;
if
(
sqlite3_open
(
path
,
&
session
)
!=
SQLITE_OK
)
{
...
...
@@ -293,7 +297,10 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file,
sqlite3_bind_int
(
stmt
,
2
,
file_info
->
current_page
)
!=
SQLITE_OK
||
sqlite3_bind_int
(
stmt
,
3
,
file_info
->
page_offset
)
!=
SQLITE_OK
||
sqlite3_bind_double
(
stmt
,
4
,
file_info
->
scale
)
!=
SQLITE_OK
||
sqlite3_bind_int
(
stmt
,
5
,
file_info
->
rotation
)
!=
SQLITE_OK
)
{
sqlite3_bind_int
(
stmt
,
5
,
file_info
->
rotation
)
!=
SQLITE_OK
||
sqlite3_bind_int
(
stmt
,
6
,
file_info
->
pages_per_row
)
!=
SQLITE_OK
||
sqlite3_bind_double
(
stmt
,
7
,
file_info
->
position_x
)
!=
SQLITE_OK
||
sqlite3_bind_double
(
stmt
,
8
,
file_info
->
position_y
)
!=
SQLITE_OK
)
{
sqlite3_finalize
(
stmt
);
girara_error
(
"Failed to bind arguments."
);
return
false
;
...
...
@@ -339,6 +346,9 @@ sqlite_get_fileinfo(zathura_database_t* db, const char* file,
file_info
->
page_offset
=
sqlite3_column_int
(
stmt
,
1
);
file_info
->
scale
=
sqlite3_column_double
(
stmt
,
2
);
file_info
->
rotation
=
sqlite3_column_int
(
stmt
,
3
);
file_info
->
pages_per_row
=
sqlite3_column_int
(
stmt
,
4
);
file_info
->
position_x
=
sqlite3_column_double
(
stmt
,
5
);
file_info
->
position_y
=
sqlite3_column_double
(
stmt
,
6
);
sqlite3_finalize
(
stmt
);
...
...
database.h
View file @
370deafb
...
...
@@ -14,6 +14,9 @@ typedef struct zathura_fileinfo_s {
unsigned
int
page_offset
;
double
scale
;
unsigned
int
rotation
;
unsigned
int
pages_per_row
;
double
position_x
;
double
position_y
;
}
zathura_fileinfo_t
;
#define ZATHURA_TYPE_DATABASE \
...
...
zathura.c
View file @
370deafb
...
...
@@ -38,8 +38,21 @@ typedef struct zathura_document_info_s
const
char
*
password
;
}
zathura_document_info_t
;
typedef
struct
page_set_delayed_s
{
zathura_t
*
zathura
;
unsigned
int
page
;
}
page_set_delayed_t
;
typedef
struct
position_set_delayed_s
{
zathura_t
*
zathura
;
zathura_fileinfo_t
file_info
;
}
position_set_delayed_t
;
static
gboolean
document_info_open
(
gpointer
data
);
static
gboolean
purge_pages
(
gpointer
data
);
static
gboolean
position_set_delayed
(
gpointer
data
);
/* function implementation */
zathura_t
*
...
...
@@ -466,7 +479,7 @@ document_open(zathura_t* zathura, const char* path, const char* password)
unsigned
int
number_of_pages
=
zathura_document_get_number_of_pages
(
document
);
/* read history file */
zathura_fileinfo_t
file_info
=
{
0
,
0
,
1
,
0
};
zathura_fileinfo_t
file_info
=
{
0
,
0
,
1
,
0
,
1
,
0
,
0
};
zathura_db_get_fileinfo
(
zathura
->
database
,
file_path
,
&
file_info
);
/* set page offset */
...
...
@@ -587,7 +600,11 @@ document_open(zathura_t* zathura, const char* path, const char* password)
/* view mode */
int
pages_per_row
=
1
;
if
(
file_info
.
pages_per_row
>
0
)
{
pages_per_row
=
file_info
.
pages_per_row
;
}
else
{
girara_setting_get
(
zathura
->
ui
.
session
,
"pages-per-row"
,
&
pages_per_row
);
}
page_widget_set_mode
(
zathura
,
pages_per_row
);
girara_set_view
(
zathura
->
ui
.
session
,
zathura
->
ui
.
page_widget_alignment
);
...
...
@@ -606,9 +623,6 @@ document_open(zathura_t* zathura, const char* path, const char* password)
/* bookmarks */
zathura_bookmarks_load
(
zathura
,
file_path
);
page_set_delayed
(
zathura
,
zathura_document_get_current_page_number
(
document
));
cb_view_vadjustment_value_changed
(
NULL
,
zathura
);
/* update title */
girara_set_window_title
(
zathura
->
ui
.
session
,
file_path
);
...
...
@@ -618,6 +632,18 @@ document_open(zathura_t* zathura, const char* path, const char* password)
girara_argument_t
argument
=
{
zathura_document_get_adjust_mode
(
document
),
NULL
};
sc_adjust_window
(
zathura
->
ui
.
session
,
&
argument
,
NULL
,
0
);
/* set position */
if
(
file_info
.
position_x
!=
0
||
file_info
.
position_y
!=
0
)
{
position_set_delayed_t
*
p
=
g_malloc0
(
sizeof
(
position_set_delayed_t
));
p
->
zathura
=
zathura
;
p
->
file_info
=
file_info
;
gdk_threads_add_idle
(
position_set_delayed
,
p
);
}
else
{
page_set_delayed
(
zathura
,
zathura_document_get_current_page_number
(
document
));
cb_view_vadjustment_value_changed
(
NULL
,
zathura
);
}
return
true
;
error_free:
...
...
@@ -704,6 +730,17 @@ document_close(zathura_t* zathura, bool keep_monitor)
file_info
.
scale
=
zathura_document_get_scale
(
zathura
->
document
);
file_info
.
rotation
=
zathura_document_get_rotation
(
zathura
->
document
);
girara_setting_get
(
zathura
->
ui
.
session
,
"pages-per-row"
,
&
(
file_info
.
pages_per_row
));
/* get position */
GtkScrolledWindow
*
window
=
GTK_SCROLLED_WINDOW
(
zathura
->
ui
.
session
->
gtk
.
view
);
GtkAdjustment
*
vadjustment
=
gtk_scrolled_window_get_vadjustment
(
window
);
GtkAdjustment
*
hadjustment
=
gtk_scrolled_window_get_hadjustment
(
window
);
file_info
.
position_x
=
gtk_adjustment_get_value
(
hadjustment
);
file_info
.
position_y
=
gtk_adjustment_get_value
(
vadjustment
);
/* save file info */
zathura_db_set_fileinfo
(
zathura
->
database
,
path
,
&
file_info
);
/* release render thread */
...
...
@@ -711,7 +748,7 @@ document_close(zathura_t* zathura, bool keep_monitor)
zathura
->
sync
.
render_thread
=
NULL
;
/* remove widgets */
gtk_container_foreach
(
GTK_CONTAINER
(
zathura
->
ui
.
page_widget
),
remove_page_from_table
,
(
gpointer
)
1
);
gtk_container_foreach
(
GTK_CONTAINER
(
zathura
->
ui
.
page_widget
),
remove_page_from_table
,
(
gpointer
)
1
);
free
(
zathura
->
pages
);
zathura
->
pages
=
NULL
;
...
...
@@ -739,12 +776,6 @@ document_close(zathura_t* zathura, bool keep_monitor)
return
true
;
}
typedef
struct
page_set_delayed_s
{
zathura_t
*
zathura
;
unsigned
int
page
;
}
page_set_delayed_t
;
static
gboolean
page_set_delayed_impl
(
gpointer
data
)
{
...
...
@@ -874,3 +905,18 @@ gboolean purge_pages(gpointer data)
}
return
TRUE
;
}
static
gboolean
position_set_delayed
(
gpointer
data
)
{
position_set_delayed_t
*
p
=
(
position_set_delayed_t
*
)
data
;
GtkScrolledWindow
*
window
=
GTK_SCROLLED_WINDOW
(
p
->
zathura
->
ui
.
session
->
gtk
.
view
);
GtkAdjustment
*
vadjustment
=
gtk_scrolled_window_get_vadjustment
(
window
);
GtkAdjustment
*
hadjustment
=
gtk_scrolled_window_get_hadjustment
(
window
);
gtk_adjustment_set_value
(
hadjustment
,
p
->
file_info
.
position_x
);
gtk_adjustment_set_value
(
vadjustment
,
p
->
file_info
.
position_y
);
return
FALSE
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment