Skip to content

Commit

Permalink
Current version of Psi+ is 1.5.2027
Browse files Browse the repository at this point in the history
It is based on:
* psi: f08f76fd
* plugins: 7a65467
* psimedia: 478567e
* resources: e32ef4b
  • Loading branch information
tehnick committed Jul 6, 2024
1 parent 54438d4 commit 317eb15
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 97 deletions.
34 changes: 26 additions & 8 deletions src/chatviewtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ bool ChatViewThemePrivate::exists()
* @param adapterPath path to directry with adapter
* @return true on success
*/
bool ChatViewThemePrivate::load(std::function<void(bool)> loadCallback)
bool ChatViewThemePrivate::load(const QString &style, std::function<void(bool)> loadCallback)
{
this->style = style;
if (!exists()) {
return false;
}
Expand Down Expand Up @@ -134,11 +135,11 @@ bool ChatViewThemePrivate::load(std::function<void(bool)> loadCallback)
"new QWebChannel(qt.webChannelTransport, function (channel) {\n"
"window.srvLoader = channel.objects.srvLoader;\n"
"window.srvUtil = channel.objects.srvUtil;\n"
"initPsiTheme().adapter.loadTheme();\n"
"initPsiTheme().adapter.loadTheme(\"%2\");\n"
"});\n"
"});\n"
"</script></head></html>")
.arg(themeType),
.arg(themeType, style),
jsLoader->serverUrl());
return true;
#else
Expand All @@ -155,11 +156,13 @@ bool ChatViewThemePrivate::load(std::function<void(bool)> loadCallback)
evaluateFromFile(sp, wv->page()->mainFrame());
}

QString resStr = wv->page()
->mainFrame()
->evaluateJavaScript("try { initPsiTheme().adapter.loadTheme(); \"ok\"; } "
"catch(e) { \"Error:\" + e + \"\\n\" + window.psiim.util.props(e); }")
.toString();
QString resStr
= wv->page()
->mainFrame()
->evaluateJavaScript(QString("try { initPsiTheme().adapter.loadTheme(\"%1\"); \"ok\"; } "
"catch(e) { \"Error:\" + e + \"\\n\" + window.psiim.util.props(e); }")
.arg(style))
.toString();

if (resStr == "ok") {
return true;
Expand Down Expand Up @@ -456,6 +459,15 @@ void ChatViewJSLoader::setMetaData(const QVariantMap &map)
vl = map["stylesList"].toStringList();
if (vl.count()) {
theme->stylesList = vl;
if (theme->style.isEmpty()) {
auto const currentId = theme->provider->current().id();
auto currentStyle = currentId.isEmpty() ? QString {} : theme->provider->current().style();
if (vl.contains(currentStyle)) {
theme->style = currentStyle;
} else {
theme->style = vl[0];
}
}
}
}

Expand Down Expand Up @@ -540,6 +552,12 @@ QVariantMap ChatViewJSLoader::checkFilesExist(const QStringList &files, const QS
return ret;
}

QStringList ChatViewJSLoader::listFiles()
{
QScopedPointer<Theme::ResourceLoader> loader(Theme(theme).resourceLoader());
return loader->listAll();
}

QString ChatViewJSLoader::getFileContents(const QString &name) const { return QString(Theme(theme).loadData(name)); }

QString ChatViewJSLoader::getFileContentsFromAdapterDir(const QString &name) const
Expand Down
3 changes: 2 additions & 1 deletion src/chatviewtheme_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public slots:
QString getFileContents(const QString &name) const;
QString getFileContentsFromAdapterDir(const QString &name) const;
void setTransparent();
QStringList listFiles();
};

// JS Bridge object emedded by theme. Has any logic unrelted to contact itself
Expand Down Expand Up @@ -160,7 +161,7 @@ class ChatViewThemePrivate : public ThemePrivate {
~ChatViewThemePrivate();

bool exists();
bool load(std::function<void(bool)> loadCallback);
bool load(const QString &style, std::function<void(bool)> loadCallback);
bool hasPreview() const;
QWidget *previewWidget();

Expand Down
18 changes: 11 additions & 7 deletions src/chatviewthemeprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ Theme ChatViewThemeProvider::theme(const QString &id)
*/
PsiThemeProvider::LoadRestult ChatViewThemeProvider::loadCurrent()
{
QString loadedId = curTheme.id();
QString themeName = PsiOptions::instance()->getOption(optionString()).toString();
if (!loadedId.isEmpty() && loadedId == themeName) {
QString loadedId = curTheme.id();
QString loadedStyle = loadedId.isEmpty() ? loadedId : curTheme.style();
QString themeName = PsiOptions::instance()->getOption(optionString()).toString();
QString style = PsiOptions::instance()->getOption(optionString() + QLatin1String("-style")).toString();
if (!loadedId.isEmpty() && loadedId == themeName && loadedStyle == style) {
return LoadSuccess; // already loaded. nothing todo
}
auto newClassic = QStringLiteral("psi/new_classic");
Expand All @@ -104,19 +106,20 @@ PsiThemeProvider::LoadRestult ChatViewThemeProvider::loadCurrent()
qDebug("Invalid theme id: %s", qPrintable(themeName));
qDebug("fallback to new_classic chatview theme");
PsiOptions::instance()->setOption(optionString(), newClassic);
style.clear();
curLoadingTheme = theme(newClassic);
} else {
qDebug("New Classic theme failed to load. No fallback..");
return LoadFailure;
}
}

bool startedLoading = curLoadingTheme.load([this, loadedId, newClassic](bool success) {
bool startedLoading = curLoadingTheme.load(style, [this, loadedId, loadedStyle, newClassic](bool success) {
auto t = curLoadingTheme;
curLoadingTheme = {};
if (success) {
curTheme = t;
if (t.id() != loadedId) {
if (t.id() != loadedId || t.style() != loadedStyle) {
emit themeChanged();
}
return;
Expand Down Expand Up @@ -144,10 +147,11 @@ void ChatViewThemeProvider::cancelCurrentLoading() { curLoadingTheme = {}; /* sh

Theme ChatViewThemeProvider::current() const { return curTheme; }

void ChatViewThemeProvider::setCurrentTheme(const QString &id)
void ChatViewThemeProvider::setCurrentTheme(const QString &id, const QString &style)
{
PsiOptions::instance()->setOption(optionString(), id);
if (!curTheme.isValid() || curTheme.id() != id) {
PsiOptions::instance()->setOption(optionString() + QLatin1String("-style"), style);
if (!curTheme.isValid() || curTheme.id() != id || curTheme.style() != style) {
loadCurrent();
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/chatviewthemeprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ class ChatViewThemeProvider : public PsiThemeProvider {
public:
ChatViewThemeProvider(PsiCon *);

const char *type() const { return "chatview"; }
const QStringList themeIds() const;
Theme theme(const QString &id);
const char *type() const override { return "chatview"; }
const QStringList themeIds() const override;
Theme theme(const QString &id) override;

LoadRestult loadCurrent();
void unloadCurrent();
void cancelCurrentLoading();
Theme current() const; // currently loaded theme
LoadRestult loadCurrent() override;
void unloadCurrent() override;
void cancelCurrentLoading() override;
Theme current() const override; // currently loaded theme

void setCurrentTheme(const QString &);
virtual int screenshotWidth() const { return 512; } // hack
void setCurrentTheme(const QString &, const QString &style = {}) override;
virtual int screenshotWidth() const override { return 512; } // hack

#ifdef WEBENGINE
QWebEngineUrlRequestInterceptor *requestInterceptor();
#endif

QString optionsName() const { return tr("Chat Message Style"); }
QString optionsDescription() const { return tr("Configure your chat theme here"); }
QString optionsName() const override { return tr("Chat Message Style"); }
QString optionsDescription() const override { return tr("Configure your chat theme here"); }

protected:
virtual const char *optionString() const { return "options.ui.chat.theme"; }
Expand Down
7 changes: 4 additions & 3 deletions src/options/opt_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ QWidget *OptionsTabAppearanceTheme::widget()
SLOT(themeSelected(QModelIndex, QModelIndex)));

connect(themesModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(modelRowsInserted(QModelIndex, int, int)));
connect(d->cmb_style, qOverload<int>(&QComboBox::currentIndexChanged), this, [this](int) { emit dataChanged(); });

QTimer::singleShot(0, unsortedModel, &PsiThemeModel::load);

Expand Down Expand Up @@ -197,8 +198,8 @@ void OptionsTabAppearanceTheme::updateStyles(const QModelIndex &index)
for (auto const &s : styles) {
d->cmb_style->addItem(s);
}
d->cmb_style->setCurrentIndex(0);
d->cmb_style->blockSignals(0);
d->cmb_style->setCurrentText(themesModel->data(index, PsiThemeModel::CurrentStyleRole).toString());
d->cmb_style->blockSignals(false);
}

void OptionsTabAppearanceTheme::applyOptions()
Expand All @@ -207,7 +208,7 @@ void OptionsTabAppearanceTheme::applyOptions()
return;

OptAppearanceThemeUI *d = static_cast<OptAppearanceThemeUI *>(w);
themesModel->setData(d->themeView->currentIndex(), true, PsiThemeModel::IsCurrent);
themesModel->setData(d->themeView->currentIndex(), d->cmb_style->currentText(), PsiThemeModel::IsCurrent);
}

void OptionsTabAppearanceTheme::restoreOptions()
Expand Down
2 changes: 1 addition & 1 deletion src/options/opt_theme.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<item>
<widget class="QLabel" name="lbl_style">
<property name="text">
<string>Style</string>
<string>Style:</string>
</property>
</widget>
</item>
Expand Down
49 changes: 26 additions & 23 deletions src/psithememodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct PsiThemeModel::Loader {
ThemeItemInfo ti;
ti.id = id;
Theme theme = provider->theme(id);
if (theme.load()) {
if (theme.load({})) { // load with default style
fillThemeInfo(ti, theme);
} else {
ti.title = ":-(";
Expand All @@ -55,11 +55,11 @@ struct PsiThemeModel::Loader {
return ti;
}

void asyncLoad(const QString &id, std::function<void(const ThemeItemInfo &)> loadCallback)
void asyncLoad(const QString &id, const QString &style, std::function<void(const ThemeItemInfo &)> loadCallback)
{
Theme theme = provider->theme(id);
themes.insert(id, theme);
if (!theme.isValid() || !theme.load([this, theme, loadCallback](bool success) {
if (!theme.isValid() || !theme.load(style, [this, theme, loadCallback](bool success) {
qDebug("%s theme loading status: %s", qPrintable(theme.id()), success ? "success" : "failure");
// TODO invent something smarter

Expand All @@ -75,15 +75,16 @@ struct PsiThemeModel::Loader {

void fillThemeInfo(ThemeItemInfo &ti, const Theme &theme) const
{
ti.id = theme.id();
ti.title = theme.title();
ti.version = theme.version();
ti.description = theme.description();
ti.authors = theme.authors();
ti.creation = theme.creation();
ti.homeUrl = theme.homeUrl();
ti.features = theme.features();
ti.stylesList = theme.stylesList();
ti.id = theme.id();
ti.title = theme.title();
ti.version = theme.version();
ti.description = theme.description();
ti.authors = theme.authors();
ti.creation = theme.creation();
ti.homeUrl = theme.homeUrl();
ti.features = theme.features();
ti.stylesList = theme.stylesList();
ti.currentStyle = theme.style();

ti.hasPreview = theme.hasPreview();
ti.isValid = true;
Expand Down Expand Up @@ -133,7 +134,12 @@ void PsiThemeModel::load()
QStringList ids = provider->themeIds();
qDebug() << ids;
for (const QString &id : ids) {
loader->asyncLoad(id, [this](const ThemeItemInfo &ti) {
QString style;
if (id == provider->current().id()) {
style = provider->current().style();
}

loader->asyncLoad(id, style, [this](const ThemeItemInfo &ti) {
if (ti.isValid) {
beginInsertRows(QModelIndex(), themesInfo.size(), themesInfo.size());
themesInfo.append(ti);
Expand Down Expand Up @@ -197,10 +203,10 @@ QVariant PsiThemeModel::data(const QModelIndex &index, int role) const
}
case IsCurrent:
return themesInfo[index.row()].isCurrent;
case StylesListRole: {
const ThemeItemInfo &ti = themesInfo[index.row()];
return ti.stylesList;
}
case StylesListRole:
return themesInfo[index.row()].stylesList;
case CurrentStyleRole:
return themesInfo[index.row()].currentStyle;
}
return QVariant();
}
Expand All @@ -212,12 +218,9 @@ bool PsiThemeModel::setData(const QModelIndex &index, const QVariant &value, int
}

if (role == IsCurrent) {
if (value.toBool()) {
provider->setCurrentTheme(themesInfo[index.row()].id);
return true;
} else {
// TODO set fallback / default
}
auto style = value.toString();
provider->setCurrentTheme(themesInfo[index.row()].id, style);
return true;
}

return false;
Expand Down
10 changes: 9 additions & 1 deletion src/psithememodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct ThemeItemInfo {
QString homeUrl;
QStringList features;
QStringList stylesList;
QString currentStyle;

bool hasPreview;
bool isValid = false;
Expand All @@ -48,7 +49,14 @@ class PsiThemeModel : public QAbstractListModel {
Q_OBJECT

public:
enum ThemeRoles { IdRole = Qt::UserRole + 1, HasPreviewRole, TitleRole, IsCurrent, StylesListRole };
enum ThemeRoles {
IdRole = Qt::UserRole + 1,
HasPreviewRole,
TitleRole,
IsCurrent,
CurrentStyleRole,
StylesListRole
};

PsiThemeModel(PsiThemeProvider *provider, QObject *parent);
~PsiThemeModel();
Expand Down
16 changes: 8 additions & 8 deletions src/psithemeprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class PsiThemeProvider : public QObject {

inline PsiCon *psi() const { return _psi; }

virtual const char *type() const = 0;
virtual Theme theme(const QString &id) = 0; // make new theme
virtual const QStringList themeIds() const = 0;
virtual LoadRestult loadCurrent() = 0;
virtual void unloadCurrent() = 0;
virtual void cancelCurrentLoading() = 0;
virtual Theme current() const = 0;
virtual void setCurrentTheme(const QString &) = 0;
virtual const char *type() const = 0;
virtual Theme theme(const QString &id) = 0; // make new theme
virtual const QStringList themeIds() const = 0;
virtual LoadRestult loadCurrent() = 0;
virtual void unloadCurrent() = 0;
virtual void cancelCurrentLoading() = 0;
virtual Theme current() const = 0;
virtual void setCurrentTheme(const QString &, const QString &style = {}) = 0;

virtual bool threadedLoading() const;
virtual int screenshotWidth() const;
Expand Down
8 changes: 5 additions & 3 deletions src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ Theme::State Theme::state() const

bool Theme::exists() { return d && d->exists(); }

bool Theme::load()
bool Theme::load(const QString &style)
{
if (!d) {
return false;
}
return d->load();
return d->load(style);
}

bool Theme::load(std::function<void(bool)> loadCallback) { return d->load(loadCallback); }
bool Theme::load(const QString &style, std::function<void(bool)> loadCallback) { return d->load(style, loadCallback); }

bool Theme::hasPreview() const { return d->hasPreview(); }

Expand Down Expand Up @@ -191,6 +191,8 @@ const QStringList &Theme::features() const { return d->features; }

const QStringList &Theme::stylesList() const { return d->stylesList; }

const QString &Theme::style() const { return d->style; }

PsiThemeProvider *Theme::themeProvider() const { return d->provider; }

/**
Expand Down
Loading

0 comments on commit 317eb15

Please sign in to comment.