Skip to content

Commit

Permalink
Add imgSizeForType method
Browse files Browse the repository at this point in the history
This provides correct cover/thumbnail dimensions for the current device
  • Loading branch information
shermp committed Apr 18, 2024
1 parent 0405903 commit b86912e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/ndb/NDBDbus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ NDBDbus::NDBDbus(QObject* parent) : QObject(parent), QDBusContext() {
// Older firmware versions use a slightly different mangled symbol name
NDB_RESOLVE_SYMBOL("_ZN20MainWindowController11currentViewEv", nh_symoutptr(nSym.MainWindowController_currentView));
}
// Image
NDB_RESOLVE_SYMBOL("_ZN5Image11sizeForTypeERK6DeviceRK7QString", nh_symoutptr(nSym.Image__sizeForType));
}

/*!
Expand Down Expand Up @@ -925,6 +927,28 @@ void NDBDbus::rvConnectSignals(QWidget* rv) {
QObject::connect(rv, SIGNAL(pageChanged(int)), this, SIGNAL(rvPageChanged(int)), Qt::UniqueConnection);
}

/*!
* \brief Gets the image size for the device
*
* Valid strings for \a type are \c N3_FULL , \c N3_LIBRARY_FULL , \c N3_LIBRARY_GRID
*
* Returns a string in the form \c "width \c height"
*
* \since 0.3.0
*/
QString NDBDbus::imgSizeForType(QString const& type) {
QString default_ret("-1 -1");
NDB_DBUS_USB_ASSERT(default_ret);
NDB_DBUS_SYM_ASSERT(default_ret, nSym.Image__sizeForType);
bool type_valid = (type == "N3_FULL" || type == "N3_LIBRARY_FULL" || type == "N3_LIBRARY_GRID");
NDB_DBUS_ASSERT(default_ret, QDBusError::InvalidArgs, type_valid, "invalid type name. Must be one of N3_FULL, N3_LIBRARY_FULL, N3_LIBRARY_GRID");
NDB_DBUS_SYM_ASSERT(default_ret, nSym.Device__getCurrentDevice);
Device *d = nSym.Device__getCurrentDevice();
NDB_DBUS_ASSERT(default_ret, QDBusError::InternalError, d, "unable to get current device");
QSize img_size = nSym.Image__sizeForType(d, type);
return QString("%1 %2").arg(img_size.width()).arg(img_size.height());
}

/* Enum Documentation */

/*!
Expand Down
4 changes: 4 additions & 0 deletions src/ndb/NDBDbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QtDBus>
#include <QDBusContext>
#include <QLabel>
#include <QSize>
#include <QTimer>
#include "NDBCfmDlg.h"

Expand Down Expand Up @@ -110,6 +111,8 @@ class NDBDbus : public QObject, protected QDBusContext {
void pwrShutdown();
void pwrReboot();
void pwrSleep();
// Image sizes
QString imgSizeForType(QString const& type);
protected Q_SLOTS:
void handleQSWCurrentChanged(int index);
void handleQSWTimer();
Expand All @@ -134,6 +137,7 @@ class NDBDbus : public QObject, protected QDBusContext {
QWidget* (*N3Dialog__content)(N3Dialog*);
Device *(*Device__getCurrentDevice)();
QByteArray (*Device__userAgent)(Device*);
QSize (*Image__sizeForType)(Device*, QString const&);
} nSym;
QTimer *viewTimer;
bool ndbInUSBMS();
Expand Down

0 comments on commit b86912e

Please sign in to comment.