mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Linux: Force use of GNOME button layout for dialogs when running under the GNOME, UNITY or MATE desktop environments
This commit is contained in:
parent
763ce0cba4
commit
d98042f993
@ -131,13 +131,41 @@ void QProgressIndicator::paintEvent(QPaintEvent * /*event*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline QByteArray detectDesktopEnvironment()
|
||||||
|
{
|
||||||
|
const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
|
||||||
|
if (!xdgCurrentDesktop.isEmpty())
|
||||||
|
return xdgCurrentDesktop.toUpper(); // KDE, GNOME, UNITY, LXDE, MATE, XFCE...
|
||||||
|
|
||||||
|
// Classic fallbacks
|
||||||
|
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION"))
|
||||||
|
return QByteArrayLiteral("KDE");
|
||||||
|
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID"))
|
||||||
|
return QByteArrayLiteral("GNOME");
|
||||||
|
|
||||||
|
// Fallback to checking $DESKTOP_SESSION (unreliable)
|
||||||
|
const QByteArray desktopSession = qgetenv("DESKTOP_SESSION");
|
||||||
|
if (desktopSession == "gnome")
|
||||||
|
return QByteArrayLiteral("GNOME");
|
||||||
|
if (desktopSession == "xfce")
|
||||||
|
return QByteArrayLiteral("XFCE");
|
||||||
|
|
||||||
|
return QByteArrayLiteral("UNKNOWN");
|
||||||
|
}
|
||||||
|
|
||||||
class CalibreStyle: public QProxyStyle {
|
class CalibreStyle: public QProxyStyle {
|
||||||
private:
|
private:
|
||||||
QHash<int, QString> icon_map;
|
QHash<int, QString> icon_map;
|
||||||
|
QByteArray desktop_environment;
|
||||||
|
QDialogButtonBox::ButtonLayout button_layout;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CalibreStyle(QStyle *base, QHash<int, QString> icmap) : QProxyStyle(base), icon_map(icmap) {
|
CalibreStyle(QStyle *base, QHash<int, QString> icmap) : QProxyStyle(base), icon_map(icmap) {
|
||||||
setObjectName(QString("calibre"));
|
setObjectName(QString("calibre"));
|
||||||
|
desktop_environment = detectDesktopEnvironment();
|
||||||
|
button_layout = (QDialogButtonBox::ButtonLayout)QProxyStyle::styleHint(SH_DialogButtonLayout);
|
||||||
|
if (desktop_environment == QString::fromLatin1("GNOME") || desktop_environment == QString::fromLatin1("MATE") || desktop_environment == QString::fromLatin1("UNITY"))
|
||||||
|
button_layout = QDialogButtonBox::GnomeLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
int styleHint(StyleHint hint, const QStyleOption *option = 0,
|
int styleHint(StyleHint hint, const QStyleOption *option = 0,
|
||||||
@ -152,7 +180,7 @@ class CalibreStyle: public QProxyStyle {
|
|||||||
#elif defined(Q_OS_MAC)
|
#elif defined(Q_OS_MAC)
|
||||||
return QDialogButtonBox::MacLayout;
|
return QDialogButtonBox::MacLayout;
|
||||||
#endif
|
#endif
|
||||||
break;
|
return button_layout;
|
||||||
case SH_FormLayoutFieldGrowthPolicy:
|
case SH_FormLayoutFieldGrowthPolicy:
|
||||||
return QFormLayout::FieldsStayAtSizeHint; // Do not have fields expand to fill all available space in QFormLayout
|
return QFormLayout::FieldsStayAtSizeHint; // Do not have fields expand to fill all available space in QFormLayout
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user