Skip to content

Commit

Permalink
Linux: Force use of GNOME button layout for dialogs when running unde…
Browse files Browse the repository at this point in the history
…r the GNOME, UNITY or MATE desktop environments
  • Loading branch information
kovidgoyal committed Oct 26, 2014
1 parent 763ce0c commit d98042f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/calibre/gui2/progress_indicator/QProgressIndicator.cpp
Expand Up @@ -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 {
private:
QHash<int, QString> icon_map;
QByteArray desktop_environment;
QDialogButtonBox::ButtonLayout button_layout;

public:
CalibreStyle(QStyle *base, QHash<int, QString> icmap) : QProxyStyle(base), icon_map(icmap) {
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,
Expand All @@ -152,7 +180,7 @@ class CalibreStyle: public QProxyStyle {
#elif defined(Q_OS_MAC)
return QDialogButtonBox::MacLayout;
#endif
break;
return button_layout;
case SH_FormLayoutFieldGrowthPolicy:
return QFormLayout::FieldsStayAtSizeHint; // Do not have fields expand to fill all available space in QFormLayout
default:
Expand Down

0 comments on commit d98042f

Please sign in to comment.