diff --git a/Telegram/Resources/lang.txt b/Telegram/Resources/lang.txt index 9f6b83a0d..233433504 100644 --- a/Telegram/Resources/lang.txt +++ b/Telegram/Resources/lang.txt @@ -314,6 +314,7 @@ lng_context_copy_image: "Copy Image"; lng_context_close_image: "Close Image"; lng_context_cancel_download: "Cancel Download"; lng_context_show_in_folder: "Show in Folder"; +lng_context_show_in_finder: "Show in Finder"; lng_context_open_video: "Open Video"; lng_context_save_video: "Save Video As..."; lng_context_open_audio: "Open Audio"; diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 7a582b628..175914d48 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -1768,7 +1768,8 @@ void HistoryVideo::draw(QPainter &p, const HistoryItem *parent, const QString &t p.fillRect(0, _height, width, st::msgShadow, shadow->b); if (_thumbw) { - p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), data->thumb->pix(_thumbw), QRect(_thumbx, _thumby, st::mediaThumbSize, st::mediaThumbSize)); + int32 rf(cIntRetinaFactor()); + p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), data->thumb->pix(_thumbw), QRect(_thumbx * rf, _thumby * rf, st::mediaThumbSize * rf, st::mediaThumbSize * rf)); } else { p.drawPixmap(QPoint(st::mediaPadding.left(), st::mediaPadding.top()), App::sprite(), (out ? st::mediaDocOutImg : st::mediaDocInImg)); } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index d5dc43b19..065dcc8a7 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -636,7 +636,7 @@ void HistoryList::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lang(lng_context_cancel_download), this, SLOT(cancelContextDownload()))->setEnabled(true); } else { if ((lnkVideo && !lnkVideo->video()->already(true).isEmpty()) || (lnkAudio && !lnkAudio->audio()->already(true).isEmpty()) || (lnkDocument && !lnkDocument->document()->already(true).isEmpty())) { - _menu->addAction(lang(lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true); + _menu->addAction(lang(cPlatform() == dbipMac ? lng_context_show_in_finder : lng_context_show_in_folder), this, SLOT(showContextInFolder()))->setEnabled(true); } _menu->addAction(lang(lnkVideo ? lng_context_open_video : (lnkAudio ? lng_context_open_audio : lng_context_open_document)), this, SLOT(openContextFile()))->setEnabled(true); _menu->addAction(lang(lnkVideo ? lng_context_save_video : (lnkAudio ? lng_context_save_audio : lng_context_save_document)), this, SLOT(saveContextFile()))->setEnabled(true); diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 8d281b13d..d09a6581f 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -71,7 +71,7 @@ void debugLogWrite(const char *file, int32 line, const QString &v) { OutputDebugString(reinterpret_cast(msg.utf16())); #endif #ifdef Q_OS_MAC - _outputDebugString(msg.toUtf8().constData()); + objc_outputDebugString(msg.toUtf8().constData()); #endif } } diff --git a/Telegram/SourceFiles/pspecific_mac.cpp b/Telegram/SourceFiles/pspecific_mac.cpp index 02b363b3f..449ce75ef 100644 --- a/Telegram/SourceFiles/pspecific_mac.cpp +++ b/Telegram/SourceFiles/pspecific_mac.cpp @@ -130,7 +130,7 @@ posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/iconround } void PsMainWindow::psIdleTimeout() { - int64 idleTime = _idleTime(); + int64 idleTime = objc_idleTime(); if (idleTime >= 0) { if (idleTime <= IdleMsecs) { psIdle = false; @@ -147,7 +147,7 @@ bool PsMainWindow::psIsOnline(int state) const { } else if (!isVisible()) { return false; } - int64 idleTime = _idleTime(); + int64 idleTime = objc_idleTime(); LOG(("App Info: idle time %1").arg(idleTime)); if (idleTime >= 0) { if (idleTime > IdleMsecs) { @@ -1624,26 +1624,11 @@ void psPostprocessFile(const QString &name) { } void psOpenFile(const QString &name, bool openWith) { - /*std::wstring wname = QDir::toNativeSeparators(name).toStdWString(); - - if (openWith && useOpenAs) { - if (shOpenWithDialog) { - OPENASINFO info; - info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_REGISTER_EXT | OAIF_EXEC; - info.pcszClass = NULL; - info.pcszFile = wname.c_str(); - shOpenWithDialog(0, &info); - } else { - openAs_RunDLL(0, 0, wname.c_str(), SW_SHOWNORMAL); - } - } else { - ShellExecute(0, L"open", wname.c_str(), 0, 0, SW_SHOWNORMAL); - }*/ + objc_openFile(name.toUtf8().constData(), openWith); } void psShowInFolder(const QString &name) { - //QString nameEscaped = QDir::toNativeSeparators(name).replace('"', qsl("\"\"")); - //ShellExecute(0, 0, qsl("explorer").toStdWString().c_str(), (qsl("/select,") + nameEscaped).toStdWString().c_str(), 0, SW_SHOWNORMAL); + objc_showInFinder(name.toUtf8().constData(), QFileInfo(name).absolutePath().toUtf8().constData()); } void psExecUpdater() { diff --git a/Telegram/SourceFiles/pspecific_mac_p.h b/Telegram/SourceFiles/pspecific_mac_p.h index 640a10957..1e1a31a59 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.h +++ b/Telegram/SourceFiles/pspecific_mac_p.h @@ -48,6 +48,9 @@ public: }; -void _debugShowAlert(const char *utf8str); -void _outputDebugString(const char *utf8str); -int64 _idleTime(); +void objc_debugShowAlert(const char *utf8str); +void objc_outputDebugString(const char *utf8str); +int64 objc_idleTime(); + +void objc_showInFinder(const char *utf8file, const char *utf8path); +void objc_openFile(const char *utf8file, bool openwith); diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index 88caf5c54..d6b57d34e 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -18,9 +18,9 @@ Copyright (c) 2014 John Preston, https://tdesktop.com #include "stdafx.h" #include "pspecific_mac_p.h" -#include #include #include +#include @interface ObserverHelper : NSObject { } @@ -201,7 +201,7 @@ void PsMacWindowPrivate::clearNotifies(unsigned long long peer) { } } -void _debugShowAlert(const char *utf8str) { +void objc_debugShowAlert(const char *utf8str) { NSString *text = [[NSString alloc] initWithUTF8String: utf8str]; NSAlert *alert = [NSAlert alertWithMessageText:@"Debug Message" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", text]; [alert runModal]; @@ -209,7 +209,7 @@ void _debugShowAlert(const char *utf8str) { [text release]; } -void _outputDebugString(const char *utf8str) { +void objc_outputDebugString(const char *utf8str) { NSString *text = [[NSString alloc] initWithUTF8String:utf8str]; NSLog(@"%@", text); [text release]; @@ -219,7 +219,7 @@ PsMacWindowPrivate::~PsMacWindowPrivate() { delete data; } -int64 _idleTime() { // taken from https://github.com/trueinteractions/tint/issues/53 +int64 objc_idleTime() { // taken from https://github.com/trueinteractions/tint/issues/53 CFMutableDictionaryRef properties = 0; CFTypeRef obj; mach_port_t masterPort; @@ -268,3 +268,106 @@ int64 _idleTime() { // taken from https://github.com/trueinteractions/tint/issue IOObjectRelease(iter); return (result == err) ? -1 : int64(result); } + +void objc_showInFinder(const char *utf8file, const char *utf8path) { + NSString *file = [[NSString alloc] initWithUTF8String:utf8file], *path = [[NSString alloc] initWithUTF8String:utf8path]; + [[NSWorkspace sharedWorkspace] selectFile:file inFileViewerRootedAtPath:path]; + [file release]; + [path release]; +} + +@interface NSURL(CompareUrls) + +- (BOOL) isEquivalent:(NSURL *)aURL; + +@end + +@implementation NSURL(CompareUrls) + +- (BOOL) isEquivalent:(NSURL *)aURL { + if ([self isEqual:aURL]) return YES; + if ([[self scheme] caseInsensitiveCompare:[aURL scheme]] != NSOrderedSame) return NO; + if ([[self host] caseInsensitiveCompare:[aURL host]] != NSOrderedSame) return NO; + if ([[self path] compare:[aURL path]] != NSOrderedSame) return NO; + if ([[self port] compare:[aURL port]] != NSOrderedSame) return NO; + if ([[self query] compare:[aURL query]] != NSOrderedSame) return NO; + return YES; +} + +@end + +@interface ChooseApplicationDelegate : NSObject { +} + +- (id) init:(NSArray *)recommendedApps; +- (BOOL) panel:(id)sender shouldEnableURL:(NSURL *)url; +- (void) dealloc; + +@end + +@implementation ChooseApplicationDelegate { + BOOL onlyRecommended; + NSArray *apps; +} + +- (id) init:(NSArray *)recommendedApps { + if (self = [super init]) { + onlyRecommended = YES; + apps = recommendedApps; + } + return self; +} + +- (BOOL) panel:(id)sender shouldEnableURL:(NSURL *)url { + NSNumber *isDirectory; + if ([url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] && isDirectory != nil && [isDirectory boolValue]) { + if (onlyRecommended) { + CFStringRef ext = CFURLCopyPathExtension((CFURLRef)url); + NSNumber *isPackage; + if ([url getResourceValue:&isPackage forKey:NSURLIsPackageKey error:nil] && isPackage != nil && [isPackage boolValue]) { + if (apps) { + for (id app in apps) { + if ([(NSURL*)app isEquivalent:url]) { + return YES; + } + } + } + return NO; + } + } + return YES; + } + return NO; +} + +- (void) dealloc { + if (apps) { + [apps release]; + } + [super dealloc]; +} + +@end + +void objc_openFile(const char *utf8file, bool openwith) { + NSString *file = [[NSString alloc] initWithUTF8String:utf8file]; + if (openwith || [[NSWorkspace sharedWorkspace] openFile:file] == NO) { + NSURL *url = [NSURL fileURLWithPath:file]; + NSArray *apps = (NSArray*)LSCopyApplicationURLsForURL(CFURLRef(url), kLSRolesAll); + + ChooseApplicationDelegate *delegate = [[ChooseApplicationDelegate alloc] init:apps]; + NSOpenPanel *openPanel = [NSOpenPanel openPanel]; + + [openPanel setCanChooseDirectories:NO]; + [openPanel setCanChooseFiles:YES]; + [openPanel setAllowsMultipleSelection:NO]; + [openPanel setDelegate:delegate]; + [openPanel setTitle:@"Choose Application"]; + [openPanel setMessage:@"Choose an application to open the document \"blabla.png\"."]; + if ([openPanel runModal] == NSOKButton) { + NSArray *result = [openPanel URLs]; + } + [delegate release]; + } + [file release]; +} diff --git a/Telegram/SourceFiles/title.cpp b/Telegram/SourceFiles/title.cpp index 1b4f8389e..03c61d304 100644 --- a/Telegram/SourceFiles/title.cpp +++ b/Telegram/SourceFiles/title.cpp @@ -59,7 +59,6 @@ TitleWidget::TitleWidget(Window *window) , _maximize(this, window) , _restore(this, window) , _close(this, window) - , availWidth(460) , lastMaximized(!(window->windowState() & Qt::WindowMaximized)) { diff --git a/Telegram/SourceFiles/title.h b/Telegram/SourceFiles/title.h index 75aa58b54..7ce806fbf 100644 --- a/Telegram/SourceFiles/title.h +++ b/Telegram/SourceFiles/title.h @@ -84,8 +84,6 @@ private: RestoreBtn _restore; CloseBtn _close; - int32 availWidth; - bool lastMaximized; };