PDA

View Full Version : QMAKE_INFO_PLIST undocumented function



patrik08
3rd June 2007, 11:04
To open documents on window i can catch on main arguments to open file.. this is ok...
And to set other extension to the new application i use the installer and if i click the document is open ok. :) super!

Now on mac after qt4 to drag document to the dock or open by normal click on finder the operation is more complicated....
On qt3 i found a sample hot to drag file on dock.. this link
http://doc.trolltech.com/qq/qq12-mac-events.html this method not run on qt4 :crying:

on mac to associate my new doc type *.sdat i found on google this way:

on pro file i insert an other info.plist xml file to bring icon to new file type and to open application on finder by click the file.... this run ... the app start but a empty file is here.. and main arguments not work!

to find this Hack .. i open http://www.google.com/codesearch and i search QMAKE_INFO_PLIST && macEventFilter ... assistant not say nothing about this ...

QMAKE_INFO_PLIST = resource/mac_qedit.plist



<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>sdat</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>mac_QeditIcon.icns</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>text/plain</string>
<string>text/plain utf-8</string>
</array>
<key>CFBundleTypeName</key>
<string>Text File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSIsAppleDefaultForType</key>
<true/>
</dict>
</array>




After i search / grep the qt4 source QMAKE_INFO_PLIST and i find the designer... and his associate ui file ok... now how designer open this ui file by click on finder or drag to dock from finder?

I found a designer server... , client ecc.. so much args...




/*
header...
QDesigner::QDesigner(int &argc, char **argv)
: QApplication(argc, argv),
m_server(0),
m_client(0),
m_workbench(0), suppressNewFormShow(false)
*/


QDesigner::QDesigner(int &argc, char **argv)
: QApplication(argc, argv),
m_server(0),
m_client(0),
m_workbench(0), suppressNewFormShow(false)
{
setOrganizationName(QLatin1String("Trolltech"));
setApplicationName(QLatin1String("Designer"));
QDesignerComponents::initializeResources();

#ifndef Q_WS_MAC
setWindowIcon(QIcon(QLatin1String(":/trolltech/designer/images/designer.png")));
#endif

initialize();
}




But how designer open this ui file on MAC ? undocumented function?

Must i write a server and a client to open a new document type?


Or is here the event to open the file! and not QCoreApplication::.arguments();



bool QDesigner::event(QEvent *ev)
{
bool eaten;
switch (ev->type()) {
case QEvent::FileOpen:
// set it true first since, if it's a Qt 3 form, the messagebox from convert will fire the timer.
suppressNewFormShow = true;
if (!m_workbench->readInForm(static_cast<QFileOpenEvent *>(ev)->file()))
suppressNewFormShow = false;
eaten = true;
break;
case QEvent::Close: {
QCloseEvent *closeEvent = static_cast<QCloseEvent *>(ev);
closeEvent->setAccepted(m_workbench->handleClose());
if (closeEvent->isAccepted()) {
// We're going down, make sure that we don't get our settings saved twice.
if (m_mainWindow)
m_mainWindow->setSaveSettingsOnClose(false);
eaten = QApplication::event(ev);
}
eaten = true;
break;
}
default:
eaten = QApplication::event(ev);
break;
}
return eaten;
}

marcel
3rd June 2007, 11:07
I'm not sure if I understand correctly, but on Mac when you open a file from Finder ( or drag it to the app icon in the dock ), your app will receive a mac event ( no details, sorry ).
So you must reimplement macEvent and catch this event. In this event there are passed the action type( open ) and the file(s) name(s).

So it will not be a Qt event, but a mac event.

More info on developer.apple.com, probably in the window manager reference.

Regards

marcel
3rd June 2007, 11:19
Oh, I have found it:
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleEvents/responding_aepg/chapter_6_section_4.html#//apple_ref/doc/uid/TP40001449-CH206-BEJBDEGI

See the open documents section, Listing 5-5.

Regards

patrik08
3rd June 2007, 12:20
Oh, I have found it:
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleEvents/responding_aepg/chapter_6_section_4.html#//apple_ref/doc/uid/TP40001449-CH206-BEJBDEGI

See the open documents section, Listing 5-5.

Regards

Why qt4.2 designer not use Apple Events , ui file go open and run....
to implement Apple Event on pro file must append LIBS += -framework Carbon
and designer not have it...

I like to open only file *.sdat on my app and the info.plist not have difined method open only mime apps ant tipe extension....

i suppode designer use an event like
http://doc.trolltech.com/4.2/qapplication.html#macEventFilter or event QEvent::FileOpen...

I understand only a smal piece of Cocoa objektiv C but Carbon it is an other pair of sleeves :crying:

fullmetalcoder
3rd June 2007, 14:04
So it will not be a Qt event, but a mac event.
AFAIK Qt Designer uses QFileOpenEvent which is clearly said to be related with Finder actions (or whatever you call that... I'm not familiar with Mac...:o)

patrik08
3rd June 2007, 14:06
I found its on qt4 no apple event are needet is comming all on normal event
on subclass QApplication && QCoreApplication no carbon ecc...

i write a LogEvents( const QString xml ) to see wathts of event go.... if i drag document to dock on graphics gui args on main is no needet i can catch all file on event window / mac / maybe linux is same....

all event from http://doc.trolltech.com/4.2/qevent.html#Type-enum can grab normal cross build.... QT4 is a Rolls-Royce Framework :)




#ifndef OS_APPLICATION_H
#define OS_APPLICATION_H

#include "main.h"

#include <QApplication>
#include <QtGui>
#include <QMessageBox>
#ifdef Q_WS_MAC
#include <Carbon/Carbon.h>
#endif

/* on main Q_INIT_RESOURCE(osApplication); same name osApplication.qrc */
/* to access info.plist live write append .... each extension wo app open go in ...*/

#define osApplication \
(static_cast<OS_application*>(QCoreApplication::instance()))

class OS_application : public QApplication
{
Q_OBJECT
//
public:
OS_application( int &argc, char **argv )
: QApplication(argc, argv)
{
/* QSetting setup */
QCoreApplication::setOrganizationName(_ORGANIZATIO N_NAME_);
QCoreApplication::setOrganizationDomain(_PROGRAM_N AME_DOMAINE_);
QCoreApplication::setApplicationName(_PROGRAM_NAME _);
}
protected:
bool event(QEvent *ev)
{
LogEvents( QString("normal event first ev->type() = %1").arg(ev->type()));
/* http://doc.trolltech.com/4.2/qevent.html#Type-enum 170 event resize context ecc...*/

bool eaten;
switch (ev->type()) {
case QEvent::FileOpen:
/* 126 */
LogEvents( QString("QEvent::FileOpen nr. %1 catch file \"%2\" ").arg(QEvent::FileOpen).arg(static_cast<QFileOpenEvent *>(ev)->file()));
eaten = true;
break;
case QEvent::Close: {
QCloseEvent *closeEvent = static_cast<QCloseEvent *>(ev);
eaten = true;
break;
}
default:
eaten = QApplication::event(ev);
break;
}
return eaten;
}
#ifdef Q_WS_MAC
bool macEventFilter( EventHandlerCallRef, EventRef inEvent )
{
int etype = GetEventKind(inEvent);
LogEvents( QString("mac event first GetEventKind(inEvent) = %1").arg(etype));
return false; /* default if not use */
}
#endif
private:
/* leave this outside debug by open application write 135 line of events */
bool LogEvents( const QString xml )
{
const QString fullFileName = QDir::homePath() + "/_todaylog/event.log";
if (fullFileName.contains("/", Qt::CaseInsensitive)) {
QString ultimacartellaaperta = fullFileName.left(fullFileName.lastIndexOf("/"))+"/";
QDir dira(ultimacartellaaperta);
if ( dira.mkpath(ultimacartellaaperta) ) { } else {
return false;
}
}


QString data = xml+"\n";
QFile f( fullFileName );
if ( f.open( QFile::Append | QFile::Text ) )
{
QTextStream sw( &f );
sw << data;
f.close();
return true;
}
return false;

}



};




/*

bool eaten;
UInt32 eclass = GetEventClass(inEvent);
int etype = GetEventKind(inEvent);
////////QMessageBox::warning(0,QString(_PROGRAM_NAME_),QSt ring("macEventFilter int %1").arg(etype));


if(etype == kEventAppleEvent) {
/////////allargeMacSlidewidget ! lateral thing....;
eaten = false;
}
return false;


*/

//
#endif // OS_APPLICATION_H

patrik08
3rd June 2007, 15:03
AFAIK Qt Designer uses QFileOpenEvent which is clearly said to be related with Finder actions (or whatever you call that... I'm not familiar with Mac...:o)

Ok , i found it QEvent::FileOpen id 116 ,

you must not know or are familiar with Mac .. qt4 handle all os one same way ;
incredible :) .
on subclass QApplication you find event which you do not know that they exist..

wysota
3rd June 2007, 21:10
Just thought you might want to take a look:

http://doc.trolltech.com/qq/qq18-macfeatures.html#newevents
http://doc.trolltech.com/qq/qq12-mac-events.html

Please read especially the one from QQ #12.

patrik08
4th June 2007, 11:43
Just thought you might want to take a look:

http://doc.trolltech.com/qq/qq18-macfeatures.html#newevents
http://doc.trolltech.com/qq/qq12-mac-events.html

Please read especially the one from QQ #12.


The QQ #12 is only to QT3 ... Issue 12 · Q4 2004 or QT4 was born on 2004?

I have write on wiki you see its? http://wiki.qtcentre.org/index.php?title=Open_dokument_on_Mac_OSX_Finder

The method QApplication::event( QEvent *ev ) QEvent::FileOpen 116 open file on mac & window .. maybe Linux ... so on int main(int argc, char *argv[]) GUI version is not needed to grab file from argv .... only on console apps.... or QCoreApplication:event()..

I digested all http://www.google.com/codesearch && http://sourceforge.net/index.php QT4 filter code ; and i never found Apple Event only on QT3

wysota
4th June 2007, 12:25
The QQ #12 is only to QT3 ... Issue 12 · Q4 2004 or QT4 was born on 2004?
So? It explains the reason, idea and an example implementation. You don't have to copy the code.


I have write on wiki you see its? http://wiki.qtcentre.org/index.php?title=Open_dokument_on_Mac_OSX_Finder
Yes, but we were wondering yesterday what this article is all about. You should rewrite the article and change its title to something more descriptive.


The method QApplication::event( QEvent *ev ) QEvent::FileOpen 116 open file on mac & window .. maybe Linux ... so on int main(int argc, char *argv[]) GUI version is not needed to grab file from argv .... only on console apps.... or QCoreApplication:event()..
Sorry, I don't understand what you want to say.


I digested all (...)
Was it tasty? :D