- Timestamp:
- Mar 5, 2009 10:20:35 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r17336 r17383 49 49 #include <QPainter> 50 50 #include <QTimer> 51 #include <QDesktopServices> 51 52 52 53 #include <math.h> … … 62 63 #endif 63 64 64 #if defined (Q_WS_MAC) 65 # include "VBoxUtils.h" 66 # ifdef QT_MAC_USE_COCOA 67 /** @todo Carbon -> Cocoa */ 68 # else 69 # include <Carbon/Carbon.h> // for HIToolbox/InternetConfig 70 # endif 71 #endif 65 #ifdef Q_WS_MAC 66 # include "VBoxUtils-darwin.h" 67 #endif /* Q_WS_MAC */ 72 68 73 69 #if defined (Q_WS_WIN) … … 645 641 const bool mLast; 646 642 }; 647 648 #if defined (Q_WS_WIN)649 class VBoxShellExecuteEvent : public QEvent650 {651 public:652 653 /** Constructs a regular enum event */654 VBoxShellExecuteEvent (QThread *aThread, const QString &aURL,655 bool aOk)656 : QEvent ((QEvent::Type) VBoxDefs::ShellExecuteEventType)657 , mThread (aThread), mURL (aURL), mOk (aOk)658 {}659 660 QThread *mThread;661 QString mURL;662 bool mOk;663 };664 #endif665 643 666 644 // VirtualBox callback class … … 5122 5100 bool VBoxGlobal::openURL (const QString &aURL) 5123 5101 { 5124 #if defined (Q_WS_WIN) 5125 /* We cannot use ShellExecute() on the main UI thread because we've 5126 * initialized COM with CoInitializeEx(COINIT_MULTITHREADED). See 5127 * http://support.microsoft.com/default.aspx?scid=kb;en-us;287087 5128 * for more details. */ 5129 class Thread : public QThread 5130 { 5131 public: 5132 5133 Thread (const QString &aURL, QObject *aObject) 5134 : mObject (aObject), mURL (aURL) {} 5135 5136 void run() 5137 { 5138 int rc = (int) ShellExecute (NULL, NULL, mURL.isNull() ? 0 : mURL.utf16(), 5139 NULL, NULL, SW_SHOW); 5140 bool ok = rc > 32; 5141 QApplication::postEvent 5142 (mObject, 5143 new VBoxShellExecuteEvent (this, mURL, ok)); 5144 } 5145 5146 QString mURL; 5147 QObject *mObject; 5148 }; 5149 5150 Thread *thread = new Thread (aURL, this); 5151 thread->start(); 5152 /* thread will be deleted in the VBoxShellExecuteEvent handler */ 5153 5154 return true; 5155 5156 #elif defined (Q_WS_X11) 5157 5158 static const char * const commands[] = 5159 { "kfmclient:exec", "gnome-open", "x-www-browser", "firefox", "konqueror" }; 5160 5161 for (size_t i = 0; i < RT_ELEMENTS (commands); ++ i) 5162 { 5163 QStringList args = QString(commands [i]).split (':'); 5164 args += aURL; 5165 QString command = args.takeFirst(); 5166 if (QProcess::startDetached (command, args)) 5167 return true; 5168 } 5169 5170 #elif defined (Q_WS_MAC) 5171 # ifdef QT_MAC_USE_COCOA 5172 /** @todo Carbon -> Cocoa */ 5173 # else /* !QT_MAC_USE_COCOA */ 5174 5175 /* The code below is taken from Psi 0.10 sources 5176 * (http://www.psi-im.org) */ 5177 5178 /* Use Internet Config to hand the URL to the appropriate application, as 5179 * set by the user in the Internet Preferences pane. 5180 * NOTE: ICStart could be called once at Psi startup, saving the 5181 * ICInstance in a global variable, as a minor optimization. 5182 * ICStop should then be called at Psi shutdown if ICStart 5183 * succeeded. */ 5184 ICInstance icInstance; 5185 OSType psiSignature = 'psi '; 5186 OSStatus error = ::ICStart (&icInstance, psiSignature); 5187 if (error == noErr) 5188 { 5189 ConstStr255Param hint (0x0); 5190 QByteArray cs = aURL.toLocal8Bit(); 5191 const char* data = cs.data(); 5192 long length = cs.length(); 5193 long start (0); 5194 long end (length); 5195 /* Don't bother testing return value (error); launched application 5196 * will report problems. */ 5197 ::ICLaunchURL (icInstance, hint, data, length, &start, &end); 5198 ICStop (icInstance); 5102 if (QDesktopServices::openUrl (aURL)) 5199 5103 return true; 5200 } 5201 # endif /* !QT_MAC_USE_COCOA */ 5202 5203 #else 5204 vboxProblem().message 5205 (NULL, VBoxProblemReporter::Error, 5206 tr ("Opening URLs is not implemented yet.")); 5207 return false; 5208 #endif 5209 5210 /* if we go here it means we couldn't open the URL */ 5104 5105 /* If we go here it means we couldn't open the URL */ 5211 5106 vboxProblem().cannotOpenURL (aURL); 5212 5107
Note:
See TracChangeset
for help on using the changeset viewer.