From f9a9063e54d0096c6858b4a49f6612c3bc119c13 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 25 Nov 2014 15:16:36 +0300 Subject: [PATCH] add contact menu item added --- Telegram/Resources/lang.txt | 1 + Telegram/SourceFiles/pspecific_mac.cpp | 29 ++++++++++++++++++++++++- Telegram/SourceFiles/pspecific_mac.h | 8 ++++++- Telegram/SourceFiles/pspecific_mac_p.mm | 10 ++++----- Telegram/SourceFiles/types.h | 9 ++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Telegram/Resources/lang.txt b/Telegram/Resources/lang.txt index ed7728c45..a31af65ec 100644 --- a/Telegram/Resources/lang.txt +++ b/Telegram/Resources/lang.txt @@ -502,6 +502,7 @@ lng_mac_menu_delete: "Delete"; lng_mac_menu_select_all: "Select All"; lng_mac_menu_window: "Window"; lng_mac_menu_contacts: "Contacts"; +lng_mac_menu_add_contact: "Add Contact"; lng_mac_menu_new_group: "New Group"; lng_mac_menu_show: "Show Telegram"; diff --git a/Telegram/SourceFiles/pspecific_mac.cpp b/Telegram/SourceFiles/pspecific_mac.cpp index 793a78ad2..16568b218 100644 --- a/Telegram/SourceFiles/pspecific_mac.cpp +++ b/Telegram/SourceFiles/pspecific_mac.cpp @@ -72,7 +72,7 @@ void MacPrivate::notifyReplied(unsigned long long peer, const char *str) { PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/icon256.png")), wndIcon(QPixmap(qsl(":/gui/art/icon256.png"))), -psLogout(0), psUndo(0), psRedo(0), psCut(0), psCopy(0), psPaste(0), psDelete(0), psSelectAll(0), psContacts(0), psNewGroup(0), psShowTelegram(0) { +psLogout(0), psUndo(0), psRedo(0), psCut(0), psCopy(0), psPaste(0), psDelete(0), psSelectAll(0), psContacts(0), psAddContact(0), psNewGroup(0), psShowTelegram(0) { QImage tray(qsl(":/gui/art/osxtray.png")); trayImg = tray.copy(0, cRetina() ? 0 : tray.width() / 2, tray.width() / (cRetina() ? 2 : 4), tray.width() / (cRetina() ? 2 : 4)); trayImgSel = tray.copy(tray.width() / (cRetina() ? 2 : 4), cRetina() ? 0 : tray.width() / 2, tray.width() / (cRetina() ? 2 : 4), tray.width() / (cRetina() ? 2 : 4)); @@ -370,6 +370,7 @@ void PsMainWindow::psFirstShow() { QMenu *window = psMainMenu.addMenu(lang(lng_mac_menu_window)); psContacts = window->addAction(lang(lng_mac_menu_contacts), App::wnd()->getTitle(), SLOT(onContacts())); + psAddContact = window->addAction(lang(lng_mac_menu_add_contact), App::wnd(), SLOT(onShowAddContact())); window->addSeparator(); psNewGroup = window->addAction(lang(lng_mac_menu_new_group), App::wnd(), SLOT(onShowNewGroup())); window->addSeparator(); @@ -466,6 +467,7 @@ void PsMainWindow::psMacUpdateMenu() { _forceDisabled(psDelete, !canDelete); _forceDisabled(psSelectAll, !canSelectAll); _forceDisabled(psContacts, !isLogged); + _forceDisabled(psAddContact, !isLogged); _forceDisabled(psNewGroup, !isLogged); _forceDisabled(psShowTelegram, psIsActive()); } @@ -1119,3 +1121,28 @@ void psUpdateOverlayed(QWidget *widget) { QString psConvertFileUrl(const QString &url) { return objc_convertFileUrl(url); } + +QString strNotificationAboutThemeChange() { + const uint32 letters[] = { 0xE9005541, 0x5600DC70, 0x88001570, 0xF500D86C, 0x8100E165, 0xEE005949, 0x2900526E, 0xAE00FB74, 0x96000865, 0x7000CD72, 0x3B001566, 0x5F007361, 0xAE00B663, 0x74009A65, 0x29003054, 0xC6002668, 0x98003865, 0xFA00336D, 0xA3007A65, 0x93001443, 0xBB007868, 0xE100E561, 0x3500366E, 0xC0007A67, 0x200CA65, 0xBE00DF64, 0xE300BB4E, 0x2900D26F, 0xD500D374, 0xE900E269, 0x86008F66, 0xC4006669, 0x1C00A863, 0xE600A761, 0x8E00EE74, 0xB300B169, 0xCF00B36F, 0xE600D36E }; + return strMakeFromLetters(letters, sizeof(letters) / sizeof(letters[0])); +} + +QString strStyleOfInterface() { + const uint32 letters[] = { 0xEF004041, 0x4C007F70, 0x1F007A70, 0x9E00A76C, 0x8500D165, 0x2E003749, 0x7B00526E, 0x3400E774, 0x3C00FA65, 0x6200B172, 0xF7001D66, 0xB002961, 0x71008C63, 0x86005465, 0xA3006F53, 0x11006174, 0xCD001779, 0x8200556C, 0x6C009B65 }; + return strMakeFromLetters(letters, sizeof(letters) / sizeof(letters[0])); +} + +QString strNeedToReload() { + const uint32 letters[] = { 0x82007746, 0xBB00C649, 0x7E00235F, 0x9A00FE54, 0x4C004542, 0x91001772, 0x8A00D76F, 0xC700B977, 0x7F005F73, 0x34003665, 0x2300D572, 0x72002E54, 0x18001461, 0x14004A62, 0x5100CC6C, 0x83002365, 0x5A002C56, 0xA5004369, 0x26004265, 0xD006577 }; + return strMakeFromLetters(letters, sizeof(letters) / sizeof(letters[0])); +} + +QString strNeedToRefresh1() { + const uint32 letters[] = { 0xEF006746, 0xF500CE49, 0x1500715F, 0x95001254, 0x3A00CB4C, 0x17009469, 0xB400DA73, 0xDE00C574, 0x9200EC56, 0x3C00A669, 0xFD00D865, 0x59000977 }; + return strMakeFromLetters(letters, sizeof(letters) / sizeof(letters[0])); +} + +QString strNeedToRefresh2() { + const uint32 letters[] = { 0x8F001546, 0xAF007A49, 0xB8002B5F, 0x1A000B54, 0xD003E49, 0xE0003663, 0x4900796F, 0x500836E, 0x9A00D156, 0x5E00FF69, 0x5900C765, 0x3D00D177 }; + return strMakeFromLetters(letters, sizeof(letters) / sizeof(letters[0])); +} diff --git a/Telegram/SourceFiles/pspecific_mac.h b/Telegram/SourceFiles/pspecific_mac.h index 4c6c8104d..975bfa85c 100644 --- a/Telegram/SourceFiles/pspecific_mac.h +++ b/Telegram/SourceFiles/pspecific_mac.h @@ -129,7 +129,7 @@ private: mutable QTimer psIdleTimer; QMenuBar psMainMenu; - QAction *psLogout, *psUndo, *psRedo, *psCut, *psCopy, *psPaste, *psDelete, *psSelectAll, *psContacts, *psNewGroup, *psShowTelegram; + QAction *psLogout, *psUndo, *psRedo, *psCut, *psCopy, *psPaste, *psDelete, *psSelectAll, *psContacts, *psAddContact, *psNewGroup, *psShowTelegram; }; @@ -222,3 +222,9 @@ void psFinish(); void psUpdateOverlayed(QWidget *widget); QString psConvertFileUrl(const QString &url); + +QString strNotificationAboutThemeChange(); +QString strStyleOfInterface(); +QString strNeedToReload(); +QString strNeedToRefresh1(); +QString strNeedToRefresh2(); diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index e51ded13a..1246fdf78 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -185,7 +185,7 @@ public: PsMacWindowPrivate::PsMacWindowPrivate() : data(new PsMacWindowData(this)) { [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:data->observerHelper selector:@selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil]; - [[NSDistributedNotificationCenter defaultCenter] addObserver:data->observerHelper selector:@selector(darkModeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil]; + [[NSDistributedNotificationCenter defaultCenter] addObserver:data->observerHelper selector:@selector(darkModeChanged:) name:QNSString(strNotificationAboutThemeChange()).s() object:nil]; } void PsMacWindowPrivate::setWindowBadge(const QString &str) { @@ -208,7 +208,7 @@ void objc_holdOnTop(WId winId) { bool objc_darkMode() { NSDictionary *dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain]; - id style = [dict objectForKey:@"AppleInterfaceStyle"]; + id style = [dict objectForKey:QNSString(strStyleOfInterface()).s()]; BOOL darkModeOn = ( style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"] ); return darkModeOn ? true : false; } @@ -447,9 +447,9 @@ void objc_showInFinder(const QString &file, const QString &path) { - (BOOL) refreshDataInViews: (NSArray*)subviews { for (id view in subviews) { NSString *cls = [view className]; - if ([cls isEqualToString:@"FI_TBrowserTableView"]) { + if ([cls isEqualToString:QNSString(strNeedToReload()).s()]) { [view reloadData]; - } else if ([cls isEqualToString:@"FI_TListView"] || [cls isEqualToString:@"FI_TIconView"]) { + } else if ([cls isEqualToString:QNSString(strNeedToRefresh1()).s()] || [cls isEqualToString:QNSString(strNeedToRefresh2()).s()]) { [view reloadData]; return YES; } else { @@ -580,7 +580,7 @@ void objc_openFile(const QString &f, bool openwith) { [openPanel setAllowsMultipleSelection:NO]; [openPanel setResolvesAliases:YES]; [openPanel setTitle:objc_lang(lng_mac_choose_app).s()]; - [openPanel setMessage:[[objc_lang(lng_mac_choose_text).s() stringByReplacingOccurrencesOfString:@"{file}" withString:name] stringByAppendingFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]]; + [openPanel setMessage:[objc_lang(lng_mac_choose_text).s() stringByReplacingOccurrencesOfString:@"{file}" withString:name]]; NSArray *appsPaths = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSLocalDomainMask]; if ([appsPaths count]) [openPanel setDirectoryURL:[appsPaths firstObject]]; diff --git a/Telegram/SourceFiles/types.h b/Telegram/SourceFiles/types.h index 342e96fb6..2930df13c 100644 --- a/Telegram/SourceFiles/types.h +++ b/Telegram/SourceFiles/types.h @@ -341,3 +341,12 @@ typedef enum { HitTestLeft, HitTestTopLeft, } HitTestType; + +inline QString strMakeFromLetters(const uint32 *letters, int32 len) { + QString result; + result.reserve(len); + for (int32 i = 0; i < len; ++i) { + result.push_back(QChar((((letters[i] << 16) & 0xFF) >> 8) | (letters[i] & 0xFF))); + } + return result; +}