removing telegram.desktop when adding telegramdesktop.desktop, fixed libappindicator and libunity usage

This commit is contained in:
John Preston 2015-01-16 19:46:01 +03:00
parent dfd6936d64
commit 1ca86a2390
7 changed files with 90 additions and 17 deletions

View File

@ -46,7 +46,11 @@ int main(int argc, char *argv[]) {
for (int32 i = 0; i < argc; ++i) {
LOG(("Argument: %1").arg(QString::fromLocal8Bit(argv[i])));
}
}
QStringList errs = psInitErrors();
for (int32 i = 0, l = errs.size(); i < l; ++i) {
LOG(("Init Error: %1").arg(errs.at(i)));
}
}
DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession()));

View File

@ -171,12 +171,19 @@ namespace {
typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id);
f_unity_launcher_entry_get_for_desktop_id ps_unity_launcher_entry_get_for_desktop_id = 0;
QStringList _initErrors;
template <typename TFunction>
bool loadFunction(QLibrary &lib, const char *name, TFunction &func) {
if (!lib.isLoaded()) return false;
func = (TFunction)lib.resolve(name);
return !!func;
if (func) {
return true;
} else {
_initErrors.push_back(QString("Failed to load '%1' function!").arg(name));
return false;
}
}
void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) {
@ -322,8 +329,11 @@ namespace {
setupUnity();
}
void setupGTK() {
QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"));
if (!lib_gtk.load()) return;
QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"), 1, 0);
if (!lib_gtk.load()) {
_initErrors.push_back(QString("Failed to load 'gtk-x11-2.0' library!"));
return;
}
if (!loadFunction(lib_gtk, "gtk_init_check", ps_gtk_init_check)) return;
if (!loadFunction(lib_gtk, "gtk_menu_new", ps_gtk_menu_new)) return;
@ -341,7 +351,12 @@ namespace {
if (!loadFunction(lib_gtk, "g_type_check_instance_cast", ps_g_type_check_instance_cast)) return;
if (!loadFunction(lib_gtk, "g_signal_connect_data", ps_g_signal_connect_data)) return;
if (lib_indicator.load()) setupAppIndicator(lib_indicator);
if (lib_indicator.load()) {
setupAppIndicator(lib_indicator);
} else {
_initErrors.push_back(QString("Failed to load 'appindicator' library!"));
return;
}
if (!loadFunction(lib_gtk, "gdk_init_check", ps_gdk_init_check)) return;
if (!loadFunction(lib_gtk, "gdk_pixbuf_new_from_data", ps_gdk_pixbuf_new_from_data)) return;
@ -368,8 +383,11 @@ namespace {
useAppIndicator = true;
}
void setupUnity() {
QLibrary lib_unity("unity");
if (!lib_unity.load()) return;
QLibrary lib_unity("unity", 9, 0);
if (!lib_unity.load()) {
_initErrors.push_back(QString("Failed to load 'unity' library!"));
return;
}
if (!loadFunction(lib_unity, "unity_launcher_entry_get_for_desktop_id", ps_unity_launcher_entry_get_for_desktop_id)) return;
if (!loadFunction(lib_unity, "unity_launcher_entry_set_count", ps_unity_launcher_entry_set_count)) return;
@ -393,7 +411,7 @@ namespace {
};
_PsEventFilter *_psEventFilter = 0;
UnityLauncherEntry *_psUnityLauncherEntry = 0;
UnityLauncherEntry *_psUnityLauncherEntryOld = 0, *_psUnityLauncherEntry = 0;
};
PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent),
@ -529,7 +547,7 @@ void PsMainWindow::psUpdateIndicator() {
_psLastIndicatorUpdate = getms();
QFileInfo f(_trayIconImageFile());
if (f.exists()) {
QByteArray path = f.absoluteFilePath().toUtf8(), name = f.fileName().toUtf8();
QByteArray path = QFile::encodeName(f.absoluteFilePath()), name = QFile::encodeName(f.fileName());
name = name.mid(0, name.size() - 4);
ps_app_indicator_set_icon_full(_trayIndicator, path.constData(), name);
} else {
@ -543,6 +561,14 @@ void PsMainWindow::psUpdateCounter() {
int32 counter = App::histories().unreadFull;
setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
if (_psUnityLauncherEntryOld) {
if (counter > 0) {
ps_unity_launcher_entry_set_count(_psUnityLauncherEntryOld, (counter > 9999) ? 9999 : counter);
ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntryOld, TRUE);
} else {
ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntryOld, FALSE);
}
}
if (_psUnityLauncherEntry) {
if (counter > 0) {
ps_unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter);
@ -667,23 +693,33 @@ void PsMainWindow::psStateChanged(Qt::WindowState state) {
void PsMainWindow::psCreateTrayIcon() {
if (useAppIndicator) {
DEBUG_LOG(("Trying to create AppIndicator"));
if (ps_gtk_init_check(0, 0)) {
_trayMenu = ps_gtk_menu_new();
if (_trayMenu) {
QFileInfo f(_trayIconImageFile());
if (f.exists()) {
QByteArray path = f.absoluteFilePath().toUtf8();
QByteArray path = QFile::encodeName(f.absoluteFilePath());
_trayIndicator = ps_app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
if (!_trayIndicator) {
DEBUG_LOG(("Failed to app_indicator_new()!"));
}
} else {
useAppIndicator = false;
DEBUG_LOG(("Failed to create image file!"));
}
} else {
DEBUG_LOG(("Failed to gtk_menu_new()!"));
}
} else {
DEBUG_LOG(("Failed to gtk_init_check(0, 0)!"));
}
if (_trayMenu && _trayIndicator) {
ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE);
ps_app_indicator_set_menu(_trayIndicator, PS_GTK_MENU(_trayMenu));
useStatusIcon = false;
} else {
DEBUG_LOG(("AppIndicator failed!"));
useAppIndicator = false;
}
}
@ -732,7 +768,17 @@ void PsMainWindow::psFirstShow() {
if (useUnityCount) {
_psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop");
if (!_psUnityLauncherEntry) _psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop");
if (_psUnityLauncherEntry) {
LOG(("Found Unity Launcher entry telegramdesktop.desktop!"));
}
_psUnityLauncherEntryOld = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop");
if (_psUnityLauncherEntryOld) {
LOG(("Found Unity Launcher entry Telegram.desktop!"));
} else if (_psUnityLauncherEntry) {
LOG(("Could not get Unity Launcher entry!"));
}
} else {
LOG(("Not using Unity Launcher count."));
}
finished = false;
@ -1025,7 +1071,7 @@ void PsUpdateDownloader::partFailed(QNetworkReply::NetworkError e) {
}
bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c
QByteArray pathRaw = path.toUtf8();
QByteArray pathRaw = QFile::encodeName(path);
DIR *d = opendir(pathRaw.constData());
if (!d) return false;
@ -1034,7 +1080,7 @@ bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/qu
if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue;
QString fname = path + '/' + p->d_name;
QByteArray fnameRaw = fname.toUtf8();
QByteArray fnameRaw = QFile::encodeName(fname);
struct stat statbuf;
if (!stat(fnameRaw.constData(), &statbuf)) {
if (S_ISDIR(statbuf.st_mode)) {
@ -1287,6 +1333,11 @@ PsUpdateDownloader::~PsUpdateDownloader() {
reply = 0;
}
QStringList psInitErrors() {
return _initErrors;
}
void psActivateProcess(uint64 pid) {
// objc_activateProgram();
}
@ -1481,7 +1532,7 @@ bool psCheckReadyUpdate() {
return false;
}
#elif defined Q_OS_LINUX
if (!moveFile(updater.absoluteFilePath().toUtf8().constData(), curUpdater.toUtf8().constData())) {
if (!moveFile(QFile::encodeName(updater.absoluteFilePath()).constData(), QFile::encodeName(curUpdater).constData())) {
PsUpdateDownloader::clearAll();
return false;
}
@ -1498,7 +1549,7 @@ void psOpenFile(const QString &name, bool openWith) {
void psShowInFolder(const QString &name) {
App::wnd()->layerHidden();
system(("nautilus \"" + QFileInfo(name).absoluteDir().absolutePath() + "\"").toUtf8().constData());
system(("nautilus \"" + QFileInfo(name).absoluteDir().absolutePath() + "\"").toLocal8Bit().constData());
}
void psStart() {
@ -1556,6 +1607,9 @@ void psRegisterCustomScheme() {
f.close();
if (_psRunCommand(qsl("desktop-file-install --dir=%1.local/share/applications --delete-original \"%2\"").arg(home).arg(file))) {
DEBUG_LOG(("App Info: removing old .desktop file"));
QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove();
_psRunCommand(qsl("update-desktop-database %1.local/share/applications").arg(home));
_psRunCommand(qsl("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg"));
}
@ -1607,7 +1661,7 @@ bool _execUpdater(bool update = true) {
static const int MaxLen = 65536, MaxArgsCount = 128;
char path[MaxLen] = {0};
QByteArray data((cExeDir() + "Updater").toUtf8());
QByteArray data(QFile::encodeName(cExeDir() + "Updater"));
memcpy(path, data.constData(), data.size());
char *args[MaxArgsCount] = {0}, p_noupdate[] = "-noupdate", p_autostart[] = "-autostart", p_debug[] = "-debug", p_tosettings[] = "-tosettings", p_key[] = "-key", p_path[] = "-workpath";
@ -1621,7 +1675,7 @@ bool _execUpdater(bool update = true) {
if (cFromAutoStart()) args[argIndex++] = p_autostart;
if (cDebug()) args[argIndex++] = p_debug;
if (cDataFile() != (cTestMode() ? qsl("data_test") : qsl("data"))) {
QByteArray dataf = cDataFile().toUtf8();
QByteArray dataf = QFile::encodeName(cDataFile());
if (dataf.size() < MaxLen) {
memcpy(p_datafile, dataf.constData(), dataf.size());
args[argIndex++] = p_key;

View File

@ -175,6 +175,8 @@ private:
};
QStringList psInitErrors();
void psActivateProcess(uint64 pid = 0);
QString psLocalServerPrefix();
QString psCurrentCountry();

View File

@ -978,6 +978,11 @@ PsUpdateDownloader::~PsUpdateDownloader() {
reply = 0;
}
QStringList psInitErrors() {
return QStringList();
}
void psActivateProcess(uint64 pid) {
objc_activateProgram();
}

View File

@ -199,6 +199,8 @@ private:
};
QStringList psInitErrors();
void psActivateProcess(uint64 pid = 0);
QString psLocalServerPrefix();
QString psCurrentCountry();

View File

@ -1778,6 +1778,10 @@ namespace {
}
}
QStringList psInitErrors() {
return QStringList();
}
void psActivateProcess(uint64 pid) {
if (pid) {
::EnumWindows((WNDENUMPROC)_ActivateProcess, (LPARAM)&pid);

View File

@ -176,6 +176,8 @@ private:
};
QStringList psInitErrors();
void psActivateProcess(uint64 pid = 0);
QString psLocalServerPrefix();
QString psCurrentCountry();