qBittorrent
MacUtils Namespace Reference

Functions

QPixmap pixmapForExtension (const QString &ext, const QSize &size)
 
void overrideDockClickHandler (bool(*dockClickHandler)(id, SEL,...))
 
void displayNotification (const QString &title, const QString &message)
 
void openFiles (const QSet< QString > &pathsList)
 
QString badgeLabelText ()
 
void setBadgeLabelText (const QString &text)
 

Function Documentation

◆ badgeLabelText()

QString MacUtils::badgeLabelText ( )

Definition at line 111 of file macutilities.mm.

112  {
113  return QString::fromNSString(NSApp.dockTile.badgeLabel);
114  }

Referenced by MainWindow::reloadSessionStats().

Here is the caller graph for this function:

◆ displayNotification()

void MacUtils::displayNotification ( const QString &  title,
const QString &  message 
)

Definition at line 85 of file macutilities.mm.

86  {
87  @autoreleasepool
88  {
89  NSUserNotification *notification = [[NSUserNotification alloc] init];
90  notification.title = title.toNSString();
91  notification.informativeText = message.toNSString();
92  notification.soundName = NSUserNotificationDefaultSoundName;
93 
94  [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
95  }
96  }

Referenced by MainWindow::showNotificationBalloon().

Here is the caller graph for this function:

◆ openFiles()

void MacUtils::openFiles ( const QSet< QString > &  pathsList)

Definition at line 98 of file macutilities.mm.

99  {
100  @autoreleasepool
101  {
102  NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()];
103 
104  for (const auto &path : pathsList)
105  [pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]];
106 
107  [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
108  }
109  }

Referenced by anonymous_namespace{transferlistwidget.cpp}::openDestinationFolder(), PropertiesWidget::openParentFolder(), and TransferListWidget::openSelectedTorrentsFolder().

Here is the caller graph for this function:

◆ overrideDockClickHandler()

void MacUtils::overrideDockClickHandler ( bool(*)(id, SEL,...)  dockClickHandler)

Definition at line 59 of file macutilities.mm.

60  {
61  NSApplication *appInst = [NSApplication sharedApplication];
62 
63  if (!appInst)
64  return;
65 
66  Class delClass = [[appInst delegate] class];
67  SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
68 
69  if (class_getInstanceMethod(delClass, shouldHandle))
70  {
71  if (class_replaceMethod(delClass, shouldHandle, reinterpret_cast<IMP>(dockClickHandler), "B@:"))
72  qDebug("Registered dock click handler (replaced original method)");
73  else
74  qWarning("Failed to replace method for dock click handler");
75  }
76  else
77  {
78  if (class_addMethod(delClass, shouldHandle, reinterpret_cast<IMP>(dockClickHandler), "B@:"))
79  qDebug("Registered dock click handler");
80  else
81  qWarning("Failed to register dock click handler");
82  }
83  }

◆ pixmapForExtension()

QPixmap MacUtils::pixmapForExtension ( const QString &  ext,
const QSize &  size 
)

Definition at line 43 of file macutilities.mm.

44  {
45  @autoreleasepool
46  {
47  NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()];
48  if (image)
49  {
50  NSRect rect = NSMakeRect(0, 0, size.width(), size.height());
51  CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil];
52  return QPixmap::fromImage(qt_mac_toQImage(cgImage));
53  }
54 
55  return QPixmap();
56  }
57  }
QImage qt_mac_toQImage(CGImageRef image)

References qt_mac_toQImage().

Here is the call graph for this function:

◆ setBadgeLabelText()

void MacUtils::setBadgeLabelText ( const QString &  text)

Definition at line 116 of file macutilities.mm.

117  {
118  NSApp.dockTile.badgeLabel = text.toNSString();
119  }

Referenced by MainWindow::reloadSessionStats().

Here is the caller graph for this function: