Fix torrent loading on Mac OS X (closes #1011229)

This commit is contained in:
Christophe Dumez 2012-06-24 15:03:12 +03:00
parent 81a5201e41
commit 1d9ef166bd
4 changed files with 25 additions and 2 deletions

View file

@ -52,6 +52,8 @@
<string>qbittorrent</string>
<key>CFBundleIdentifier</key>
<string>org.qbittorrent</string>
<key>NSAppleScriptEnabled</key>
<string>YES</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2006-2012 Christophe Dumez</string>
<key>UTExportedTypeDeclarations</key>

View file

@ -307,6 +307,9 @@ int main(int argc, char *argv[]){
QObject::connect(&app, SIGNAL(messageReceived(const QString&)),
&window, SLOT(processParams(const QString&)));
app.setActivationWindow(&window);
#ifdef Q_WS_MAC
static_cast<QMacApplication*>(&app)->setReadyToProcessEvents();
#endif // Q_WS_MAC
#else
// Load Headless class
HeadlessLoader loader(torrentCmdLine);

View file

@ -34,11 +34,21 @@
#include "qmacapplication.h"
QMacApplication::QMacApplication(QString appid, int &argc, char** argv) :
QtSingleApplication(appid, argc, argv)
QtSingleApplication(appid, argc, argv),
m_readyToProcessEvents(false)
{
qDebug("Constructing a QMacApplication to receive file open events");
}
void QMacApplication::setReadyToProcessEvents()
{
m_readyToProcessEvents = true;
if (!m_torrentsQueue.isEmpty()) {
emit newFileOpenMacEvent(m_torrentsQueue.join("|"));
m_torrentsQueue.clear();
}
}
bool QMacApplication::event(QEvent * ev) {
switch (ev->type()) {
case QEvent::FileOpen:
@ -49,7 +59,10 @@ bool QMacApplication::event(QEvent * ev) {
path = static_cast<QFileOpenEvent *>(ev)->url().toString();
}
qDebug("Received a mac file open event: %s", qPrintable(path));
emit newFileOpenMacEvent(path);
if (m_readyToProcessEvents)
emit newFileOpenMacEvent(path);
else
m_torrentsQueue.append(path);
return true;
}
default:

View file

@ -31,12 +31,14 @@
#define QMACAPPLICATION_H
#include "qtsingleapplication.h"
#include <QStringList>
class QMacApplication : public QtSingleApplication
{
Q_OBJECT
public:
explicit QMacApplication(QString appid, int &argc, char** argv);
void setReadyToProcessEvents();
signals:
void newFileOpenMacEvent(const QString &path);
@ -44,6 +46,9 @@ signals:
protected:
bool event(QEvent *);
private:
bool m_readyToProcessEvents;
QStringList m_torrentsQueue;
};
#endif // QMACAPPLICATION_H