Skip to content

Commit 63cff9d

Browse files
committed
well lets just modernize the UI
1 parent 1767407 commit 63cff9d

File tree

13 files changed

+520
-366
lines changed

13 files changed

+520
-366
lines changed

meson.build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ add_project_arguments([
2222
'-Wno-deprecated',
2323
'-Wno-error=deprecated-declarations',
2424
# GTK4 migration debugging flags - DISABLED for now as they may cause issues
25-
# '-DGDK_DISABLE_DEPRECATED',
26-
# '-DGTK_DISABLE_DEPRECATED',
27-
# '-DG_ENABLE_DIAGNOSTIC=1',
25+
'-DGDK_DISABLE_DEPRECATED',
26+
'-DGTK_DISABLE_DEPRECATED',
27+
'-DG_ENABLE_DIAGNOSTIC=1',
2828
], language : 'cpp')
2929

3030
# Dependencies with version requirements

src/Config.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,33 @@
2525

2626
#include <glib.h>
2727

28-
#define PACKAGE_DATA_DIR "/usr/local/share"
29-
#define PACKAGE_LOCALE_DIR "/usr/local/share/locale"
28+
// These are now defined in config.h (generated by Meson)
29+
// Do NOT redefine them here to avoid warnings
30+
// #define PACKAGE_DATA_DIR "/usr/local/share"
31+
// #define PACKAGE_LOCALE_DIR "/usr/local/share/locale"
32+
// #define PACKAGE_NAME "epdfview"
33+
// #define PACKAGE_VERSION "0.3.0"
34+
// #define PACKAGE "epdfview"
35+
// #define DATADIR PACKAGE_DATA_DIR
36+
// #define LOCALEDIR PACKAGE_LOCALE_DIR
37+
// #define VERSION PACKAGE_VERSION
38+
39+
// For compatibility, we keep PACKAGE_* as aliases to the config.h values
40+
#ifndef PACKAGE_DATA_DIR
41+
#define PACKAGE_DATA_DIR DATADIR
42+
#endif
43+
#ifndef PACKAGE_LOCALE_DIR
44+
#define PACKAGE_LOCALE_DIR LOCALEDIR
45+
#endif
46+
#ifndef PACKAGE_VERSION
47+
#define PACKAGE_VERSION VERSION
48+
#endif
49+
#ifndef PACKAGE_NAME
3050
#define PACKAGE_NAME "epdfview"
31-
#define PACKAGE_VERSION "0.3.0"
51+
#endif
52+
#ifndef PACKAGE
3253
#define PACKAGE "epdfview"
33-
#define DATADIR PACKAGE_DATA_DIR
34-
#define LOCALEDIR PACKAGE_LOCALE_DIR
35-
#define VERSION PACKAGE_VERSION
54+
#endif
3655

3756
namespace ePDFView
3857
{

src/IDocument.cxx

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,36 +1116,8 @@ IDocument::goToNextPage ()
11161116
}
11171117

11181118
// Structure to hold data for async page loading
1119-
typedef struct {
1120-
IDocument* document;
1121-
gint pageNum;
1122-
} AsyncPageLoadData;
1123-
1124-
static gboolean async_go_to_page(gpointer user_data) {
1125-
AsyncPageLoadData* data = static_cast<AsyncPageLoadData*>(user_data);
1126-
IDocument* doc = data->document;
1127-
gint pageNum = data->pageNum;
1128-
1129-
// Only proceed if the page number is valid and different from current
1130-
if (pageNum != doc->getCurrentPageNum() && 1 <= pageNum && pageNum <= doc->getNumPages()) {
1131-
// Go to the target page using the public method
1132-
doc->goToPage(pageNum);
1133-
1134-
// The document will handle caching of pages automatically through its internal logic
1135-
// We don't need to manually call addPageToCache as it's handled by the document class
1136-
1137-
// Trigger a refresh of the view to show the new page
1138-
if (doc->getCurrentPage() != NULL) {
1139-
doc->notifyPageChanged();
1140-
}
1141-
}
1142-
1143-
// Free the data structure
1144-
delete data;
1145-
1146-
// Return FALSE to remove this idle function
1147-
return G_SOURCE_REMOVE;
1148-
}
1119+
///
1120+
/// @brief Goes to the document's last page.
11491121

11501122
///
11511123
/// @brief Goes to a document page.
@@ -1160,9 +1132,23 @@ static gboolean async_go_to_page(gpointer user_data) {
11601132
void
11611133
IDocument::goToPage(gint pageNum)
11621134
{
1163-
// Schedule the page load asynchronously to prevent UI freezing
1164-
AsyncPageLoadData* data = new AsyncPageLoadData{this, pageNum};
1165-
g_idle_add(async_go_to_page, data);
1135+
// Clamp to valid range and check if different from current
1136+
pageNum = CLAMP(pageNum, 1, getNumPages());
1137+
1138+
// Only change page if different - this prevents infinite loops
1139+
if (pageNum != m_CurrentPage) {
1140+
m_CurrentPage = pageNum;
1141+
1142+
addPageToCache(m_CurrentPage);
1143+
if (m_CurrentPage > 1) {
1144+
addPageToCache(m_CurrentPage - 1);
1145+
}
1146+
if (m_CurrentPage < getNumPages()) {
1147+
addPageToCache(m_CurrentPage + 1);
1148+
}
1149+
1150+
notifyPageChanged();
1151+
}
11661152
}
11671153

11681154
///
@@ -1394,6 +1380,41 @@ IDocument::zoomToWidth (gint width)
13941380
setZoom(scale);
13951381
}
13961382

1383+
///
1384+
/// @brief Zooms the document to fit the height.
1385+
///
1386+
/// It tries to get the best zoom / scale level that will let the document
1387+
/// fit into @a height, maintaining the aspect ratio.
1388+
///
1389+
/// @param height The height to fit the document to.
1390+
///
1391+
void
1392+
IDocument::zoomToHeight (gint height)
1393+
{
1394+
if (height <= 0)
1395+
{
1396+
return;
1397+
}
1398+
1399+
gdouble pageWidth;
1400+
gdouble pageHeight;
1401+
getPageSize(&pageWidth, &pageHeight);
1402+
1403+
if (pageHeight <= 0)
1404+
{
1405+
return;
1406+
}
1407+
1408+
// Calculate scale based on height while maintaining aspect ratio
1409+
gdouble scale = (gdouble)height / pageHeight;
1410+
1411+
// Apply zoom constraints
1412+
scale = CLAMP(scale, ZOOM_OUT_MAX, ZOOM_IN_MAX);
1413+
1414+
// Set the zoom level (this will trigger a redraw via notifyPageZoomed)
1415+
setZoom(scale);
1416+
}
1417+
13971418
///
13981419
/// @brief Adds a new page to the cache and starts to render it.
13991420
///

src/IDocument.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ namespace ePDFView
355355
void zoomOut (void);
356356
void zoomToFit (gint width, gint height);
357357
void zoomToWidth (gint width);
358+
void zoomToHeight (gint height);
358359

359360
gboolean hasLinkAtPosition (gint x, gint y);
360361
void activateLinkAtPosition (gint x, gint y);

src/IJob.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ IJob::dispatcher (gpointer data)
8383
void
8484
IJob::init ()
8585
{
86-
if ( !g_thread_supported () )
87-
{
88-
g_thread_init (NULL);
89-
}
86+
// GLib threads are always available in modern versions (>= 2.32)
87+
// No need to call g_thread_init() or check g_thread_supported()
9088
m_JobsQueue = g_async_queue_new ();
9189
GError *error = NULL;
9290
if ( NULL == g_thread_create (IJob::dispatcher, NULL, FALSE, &error) )

src/JobPrint.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ JobPrint::setUpPageRange ()
380380
{
381381
// Since the range is from 0 to numPages - 1, the checks for
382382
// even or odd are reversed.
383-
if ( pageNum % 2 == 0 && PRINT_EVEN_PAGE_SET == pageSet ||
384-
pageNum % 2 != 0 && PRINT_ODD_PAGE_SET == pageSet )
383+
if ( (pageNum % 2 == 0 && PRINT_EVEN_PAGE_SET == pageSet) ||
384+
(pageNum % 2 != 0 && PRINT_ODD_PAGE_SET == pageSet) )
385385
{
386386
m_PageRange[pageNum] = FALSE;
387387
}

0 commit comments

Comments
 (0)