src/qt3support/dialogs/q3filedialog_mac.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "q3filedialog.h"
       
    43 
       
    44 #ifndef QT_NO_FILEDIALOG
       
    45 
       
    46 /*****************************************************************************
       
    47   Q3FileDialog debug facilities
       
    48  *****************************************************************************/
       
    49 //#define DEBUG_FILEDIALOG_FILTERS
       
    50 
       
    51 #include "qapplication.h"
       
    52 #include <private/qapplication_p.h>
       
    53 #include <private/qt_mac_p.h>
       
    54 #include "qregexp.h"
       
    55 #include "qbuffer.h"
       
    56 #include "qstringlist.h"
       
    57 #include "qtextcodec.h"
       
    58 #include "qdesktopwidget.h"
       
    59 #include <stdlib.h>
       
    60 
       
    61 QT_BEGIN_NAMESPACE
       
    62 
       
    63 #ifndef QT_MAC_USE_COCOA
       
    64 
       
    65 /*****************************************************************************
       
    66   Externals
       
    67  *****************************************************************************/
       
    68 extern WindowPtr qt_mac_window_for(const QWidget*); //qwidget_mac.cpp
       
    69 extern const char qt3_file_dialog_filter_reg_exp[]; //qfiledialog.cpp
       
    70 
       
    71 /*****************************************************************************
       
    72   Q3FileDialog utility functions
       
    73  *****************************************************************************/
       
    74 static UInt8 *str_buffer = NULL;
       
    75 static void cleanup_str_buffer()
       
    76 {
       
    77     if(str_buffer) {
       
    78         free(str_buffer);
       
    79         str_buffer = NULL;
       
    80     }
       
    81 }
       
    82 
       
    83 // Returns the wildcard part of a filter.
       
    84 struct qt_mac_filter_name {
       
    85     QString description, regxp, filter;
       
    86 };
       
    87 static qt_mac_filter_name *extractFilter(const QString& rawFilter)
       
    88 {
       
    89     qt_mac_filter_name *ret = new qt_mac_filter_name;
       
    90     ret->filter = rawFilter;
       
    91     QString result = rawFilter;
       
    92     QRegExp r(QString::fromLatin1(qt3_file_dialog_filter_reg_exp));
       
    93     int index = r.indexIn(result);
       
    94     if(index >= 0) {
       
    95         ret->description = r.cap(1).trimmed();
       
    96         result = r.cap(2);
       
    97     }
       
    98     if(ret->description.isEmpty())
       
    99         ret->description = result;
       
   100     ret->regxp = result.replace(QLatin1Char(' '), QLatin1Char(';'));
       
   101     return ret;
       
   102 }
       
   103 
       
   104 // Makes a list of filters from ;;-separated text.
       
   105 static QList<qt_mac_filter_name*> makeFiltersList(const QString &filter)
       
   106 {
       
   107 #ifdef DEBUG_FILEDIALOG_FILTERS
       
   108     qDebug("Q3FileDialog:%d - Got filter (%s)", __LINE__, filter.latin1());
       
   109 #endif
       
   110     QString f(filter);
       
   111     if(f.isEmpty())
       
   112         f = Q3FileDialog::tr("All Files (*)");
       
   113     if(f.isEmpty())
       
   114         return QList<qt_mac_filter_name*>();
       
   115     QString sep(QLatin1String(";;"));
       
   116     int i = f.indexOf(sep, 0);
       
   117     if(i == -1) {
       
   118         sep = QLatin1String("\n");
       
   119         if(f.indexOf(sep, 0) != -1)
       
   120             i = f.indexOf(sep, 0);
       
   121     }
       
   122 
       
   123     QList<qt_mac_filter_name*> ret;
       
   124     QStringList filts = f.split(sep);
       
   125     for (QStringList::Iterator it = filts.begin(); it != filts.end(); ++it) {
       
   126         qt_mac_filter_name *filter = extractFilter((*it));
       
   127 #ifdef DEBUG_FILEDIALOG_FILTERS
       
   128         qDebug("Q3FileDialog:%d Split out filter (%d) '%s' '%s'", __LINE__, ret.count(),
       
   129                filter->regxp.latin1(), filter->description.latin1());
       
   130 #endif
       
   131         ret.append(filter);
       
   132     }
       
   133     return ret;
       
   134 }
       
   135 
       
   136 struct qt_mac_nav_filter_type {
       
   137     int index;
       
   138     QList<qt_mac_filter_name*> *filts;
       
   139 };
       
   140 
       
   141 static Boolean qt_mac_nav_filter(AEDesc *theItem, void *info,
       
   142                                              void *myd, NavFilterModes)
       
   143 {
       
   144     qt_mac_nav_filter_type *t = (qt_mac_nav_filter_type *)myd;
       
   145     if(!t || !t->filts || t->index >= t->filts->count())
       
   146         return true;
       
   147 
       
   148     NavFileOrFolderInfo *theInfo = (NavFileOrFolderInfo *)info;
       
   149     QString file;
       
   150     qt_mac_filter_name *fn = t->filts->at(t->index);
       
   151     if(!fn)
       
   152         return true;
       
   153     if(theItem->descriptorType == typeFSRef) {
       
   154         FSRef ref;
       
   155         AEGetDescData(theItem, &ref, sizeof(ref));
       
   156         if(!str_buffer) {
       
   157             qAddPostRoutine(cleanup_str_buffer);
       
   158             str_buffer = (UInt8 *)malloc(1024);
       
   159         }
       
   160         FSRefMakePath(&ref, str_buffer, 1024);
       
   161         file = QString::fromUtf8((const char *)str_buffer);
       
   162         int slsh = file.lastIndexOf(QLatin1Char('/'));
       
   163         if(slsh != -1)
       
   164             file = file.right(file.length() - slsh - 1);
       
   165     }
       
   166     QStringList reg = fn->regxp.split(QLatin1String(";"));
       
   167     for(QStringList::Iterator it = reg.begin(); it != reg.end(); ++it) {
       
   168         QRegExp rg((*it), false, true);
       
   169 #ifdef DEBUG_FILEDIALOG_FILTERS
       
   170         qDebug("Q3FileDialog:%d, asked to filter.. %s (%s)", __LINE__,
       
   171                file.latin1(), (*it).latin1());
       
   172 #endif
       
   173         if(rg.exactMatch(file))
       
   174             return true;
       
   175     }
       
   176     return (theInfo->isFolder && !file.endsWith(QLatin1String(".app")));
       
   177 }
       
   178 
       
   179 //filter UPP stuff
       
   180 static NavObjectFilterUPP mac_navFilterUPP = NULL;
       
   181 static void cleanup_navFilterUPP()
       
   182 {
       
   183     DisposeNavObjectFilterUPP(mac_navFilterUPP);
       
   184     mac_navFilterUPP = NULL;
       
   185 }
       
   186 static const NavObjectFilterUPP make_navFilterUPP()
       
   187 {
       
   188     if(mac_navFilterUPP)
       
   189         return mac_navFilterUPP;
       
   190     qAddPostRoutine(cleanup_navFilterUPP);
       
   191     return mac_navFilterUPP = NewNavObjectFilterUPP(qt_mac_nav_filter);
       
   192 }
       
   193 //event UPP stuff
       
   194 static NavEventUPP mac_navProcUPP = NULL;
       
   195 static void cleanup_navProcUPP()
       
   196 {
       
   197     DisposeNavEventUPP(mac_navProcUPP);
       
   198     mac_navProcUPP = NULL;
       
   199 }
       
   200 static bool g_nav_blocking=true;
       
   201 static void qt_mac_filedialog_event_proc(const NavEventCallbackMessage msg,
       
   202                                                      NavCBRecPtr p, NavCallBackUserData myd)
       
   203 {
       
   204     switch(msg) {
       
   205     case kNavCBPopupMenuSelect: {
       
   206         qt_mac_nav_filter_type *t = (qt_mac_nav_filter_type *)myd;
       
   207         NavMenuItemSpec *s = (NavMenuItemSpec*)p->eventData.eventDataParms.param;
       
   208         t->index = s->menuType;
       
   209 #ifdef DEBUG_FILEDIALOG_FILTERS
       
   210         qDebug("Q3FileDialog:%d - Selected a filter: %ld", __LINE__, s->menuType);
       
   211 #endif
       
   212         break; }
       
   213     case kNavCBStart:
       
   214         g_nav_blocking=true;
       
   215         break;
       
   216     case kNavCBUserAction:
       
   217         g_nav_blocking=false;
       
   218         break;
       
   219     }
       
   220 }
       
   221 static const NavEventUPP make_navProcUPP()
       
   222 {
       
   223     if(mac_navProcUPP)
       
   224         return mac_navProcUPP;
       
   225     qAddPostRoutine(cleanup_navProcUPP);
       
   226     return mac_navProcUPP = NewNavEventUPP(qt_mac_filedialog_event_proc);
       
   227 }
       
   228 
       
   229 
       
   230 extern OSErr qt_mac_create_fsref(const QString &, FSRef *); //qglobal.cpp
       
   231 
       
   232 QStringList Q3FileDialog::macGetOpenFileNames(const QString &filter, QString *pwd,
       
   233                                              QWidget *parent, const char* /*name*/,
       
   234                                              const QString& caption, QString *selectedFilter,
       
   235                                              bool multi, bool directory)
       
   236 {
       
   237     OSErr err;
       
   238     QStringList retstrl;
       
   239 
       
   240     NavDialogCreationOptions options;
       
   241     NavGetDefaultDialogCreationOptions(&options);
       
   242     options.modality = kWindowModalityAppModal;
       
   243     options.optionFlags |= kNavDontConfirmReplacement | kNavSupportPackages;
       
   244     if (!multi)
       
   245         options.optionFlags &= ~kNavAllowMultipleFiles;
       
   246     if(!caption.isEmpty())
       
   247         options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(),
       
   248                                                            caption.length());
       
   249 
       
   250     static const int w = 450, h = 350;
       
   251     options.location.h = options.location.v = -1;
       
   252     if(parent && parent->isVisible()) {
       
   253         Qt::WindowType wt = parent->window()->windowType();
       
   254         if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) {
       
   255             options.modality = kWindowModalityWindowModal;
       
   256             options.parentWindow = qt_mac_window_for(parent);
       
   257         } else {
       
   258             parent = parent->window();
       
   259             QString s = parent->windowTitle();
       
   260             options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length());
       
   261             options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
       
   262             options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);
       
   263 
       
   264             QRect r = QApplication::desktop()->screenGeometry(
       
   265                 QApplication::desktop()->screenNumber(parent));
       
   266             if(options.location.h + w > r.right())
       
   267                 options.location.h -= (options.location.h + w) - r.right() + 10;
       
   268             if(options.location.v + h > r.bottom())
       
   269                 options.location.v -= (options.location.v + h) - r.bottom() + 10;
       
   270         }
       
   271     } else if(QWidget *p = qApp->mainWidget()) {
       
   272         static int last_screen = -1;
       
   273         int scr = QApplication::desktop()->screenNumber(p);
       
   274         if(last_screen != scr) {
       
   275             QRect r = QApplication::desktop()->screenGeometry(scr);
       
   276             options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
       
   277             options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
       
   278         }
       
   279     }
       
   280 
       
   281     QList<qt_mac_filter_name*> filts = makeFiltersList(filter);
       
   282     qt_mac_nav_filter_type t;
       
   283     t.index = 0;
       
   284     t.filts = &filts;
       
   285     if(filts.count() > 1) {
       
   286         int i = 0;
       
   287         CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count());
       
   288         for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) {
       
   289             QString rg = (*it)->description;
       
   290             arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length());
       
   291         }
       
   292         options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL);
       
   293     }
       
   294 
       
   295     NavDialogRef dlg;
       
   296     if(directory) {
       
   297         if(NavCreateChooseFolderDialog(&options, make_navProcUPP(), NULL, NULL, &dlg)) {
       
   298             qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
       
   299             return retstrl;
       
   300         }
       
   301     } else {
       
   302         if(NavCreateGetFileDialog(&options, NULL, make_navProcUPP(), NULL,
       
   303                                   make_navFilterUPP(), (void *) (filts.isEmpty() ? NULL : &t),
       
   304                                   &dlg)) {
       
   305             qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
       
   306             return retstrl;
       
   307         }
       
   308     }
       
   309     if(pwd && !pwd->isEmpty()) {
       
   310         FSRef fsref;
       
   311         if(qt_mac_create_fsref(*pwd, &fsref) == noErr) {
       
   312             AEDesc desc;
       
   313             if(AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
       
   314                 NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
       
   315         }
       
   316     }
       
   317 
       
   318     NavDialogRun(dlg);
       
   319     if (selectedFilter) {
       
   320         NavMenuItemSpec navSpec;
       
   321         bzero(&navSpec, sizeof(NavMenuItemSpec));
       
   322         qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0);
       
   323         for (int i = 0; i < filts.count(); ++i) {
       
   324             const qt_mac_filter_name *filter = filts.at(i);
       
   325             if (sel_filt_name->description == filter->description
       
   326                     && sel_filt_name->regxp == filter->regxp
       
   327                     && sel_filt_name->filter == filter->filter) {
       
   328                 navSpec.menuType = i;
       
   329                 break;
       
   330             }
       
   331         }
       
   332         NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
       
   333     }
       
   334     if(options.modality == kWindowModalityWindowModal) { //simulate modality
       
   335         QWidget modal_widg(parent, __FILE__ "__modal_dlg",
       
   336                            Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
       
   337         modal_widg.createWinId();
       
   338         QApplicationPrivate::enterModal(&modal_widg);
       
   339         while(g_nav_blocking)
       
   340             qApp->processEvents(QEventLoop::WaitForMoreEvents);
       
   341         QApplicationPrivate::leaveModal(&modal_widg);
       
   342     }
       
   343 
       
   344     if(!(NavDialogGetUserAction(dlg) &
       
   345           (kNavUserActionOpen | kNavUserActionChoose | kNavUserActionNewFolder))) {
       
   346         NavDialogDispose(dlg);
       
   347         return retstrl;
       
   348     }
       
   349     NavReplyRecord ret;
       
   350     NavDialogGetReply(dlg, &ret);
       
   351     NavDialogDispose(dlg);
       
   352 
       
   353     long count;
       
   354     err = AECountItems(&(ret.selection), &count);
       
   355     if(!ret.validRecord || err != noErr || !count) {
       
   356         NavDisposeReply(&ret);
       
   357         return retstrl;
       
   358     }
       
   359 
       
   360     for(long index = 1; index <= count; index++) {
       
   361         FSRef ref;
       
   362         err = AEGetNthPtr(&(ret.selection), index, typeFSRef, 0, 0, &ref, sizeof(ref), 0);
       
   363         if(err != noErr)
       
   364             break;
       
   365 
       
   366         if(!str_buffer) {
       
   367             qAddPostRoutine(cleanup_str_buffer);
       
   368             str_buffer = (UInt8 *)malloc(1024);
       
   369         }
       
   370         FSRefMakePath(&ref, str_buffer, 1024);
       
   371         retstrl.append(QString::fromUtf8((const char *)str_buffer));
       
   372     }
       
   373     NavDisposeReply(&ret);
       
   374     if(selectedFilter)
       
   375         *selectedFilter = filts.at(t.index)->filter;
       
   376     while (!filts.isEmpty())
       
   377         delete filts.takeFirst();
       
   378     return retstrl;
       
   379 }
       
   380 
       
   381 // Copious copy and paste from qfiledialog.cpp. Fix in 4.0.
       
   382 static QString encodeFileName(const QString &fName)
       
   383 {
       
   384     QString newStr;
       
   385     QByteArray cName = fName.utf8();
       
   386     const QByteArray sChars("<>#@\"&%$:,;?={}|^~[]\'`\\*");
       
   387 
       
   388     int len = cName.length();
       
   389     if (!len)
       
   390         return QString();
       
   391     for (int i = 0; i < len ;++i) {
       
   392         uchar inCh = (uchar)cName[i];
       
   393         if (inCh >= 128 || sChars.contains(inCh))
       
   394         {
       
   395             newStr += QLatin1Char('%');
       
   396             ushort c = inCh / 16;
       
   397             c += c > 9 ? 'A' - 10 : '0';
       
   398             newStr += QLatin1Char((char)c);
       
   399             c = inCh % 16;
       
   400             c += c > 9 ? 'A' - 10 : '0';
       
   401             newStr += QLatin1Char((char)c);
       
   402         } else {
       
   403             newStr += QLatin1Char((char)inCh);
       
   404         }
       
   405     }
       
   406     return newStr;
       
   407 }
       
   408 
       
   409 QString Q3FileDialog::macGetSaveFileName(const QString &start, const QString &filter,
       
   410                                          QString *, QWidget *parent, const char* /*name*/,
       
   411                                          const QString& caption, QString *selectedFilter)
       
   412 {
       
   413     OSErr err;
       
   414     QString retstr;
       
   415     NavDialogCreationOptions options;
       
   416     NavGetDefaultDialogCreationOptions(&options);
       
   417     static const int w = 450, h = 350;
       
   418     options.optionFlags |= kNavDontConfirmReplacement;
       
   419     options.modality = kWindowModalityAppModal;
       
   420     options.location.h = options.location.v = -1;
       
   421     QString workingDir;
       
   422     QString initialSelection;
       
   423     if (!start.isEmpty()) {
       
   424         Q3UrlOperator u(encodeFileName(start));
       
   425         if (u.isLocalFile() && QFileInfo(u.path()).isDir()) {
       
   426             workingDir = start;
       
   427         } else {
       
   428             if (u.isLocalFile()) {
       
   429                 QFileInfo fi(u.dirPath());
       
   430                 if (fi.exists()) {
       
   431                     workingDir = u.dirPath();
       
   432                     initialSelection = u.fileName();
       
   433                 }
       
   434             } else {
       
   435                 workingDir = u.toString();
       
   436             }
       
   437         }
       
   438         if (!initialSelection.isEmpty())
       
   439             options.saveFileName = CFStringCreateWithCharacters(0,
       
   440                                                             (UniChar *)initialSelection.unicode(),
       
   441                                                             initialSelection.length());
       
   442     }
       
   443     if(!caption.isEmpty())
       
   444         options.windowTitle = CFStringCreateWithCharacters(NULL, (UniChar *)caption.unicode(),
       
   445                                                            caption.length());
       
   446     if(parent && parent->isVisible()) {
       
   447         Qt::WindowType wt = parent->window()->windowType();
       
   448         if (wt != Qt::Desktop && wt != Qt::Sheet && wt != Qt::Drawer) {
       
   449             options.modality = kWindowModalityWindowModal;
       
   450             options.parentWindow = qt_mac_window_for(parent);
       
   451         } else {
       
   452             parent = parent->window();
       
   453             QString s = parent->windowTitle();
       
   454             options.clientName = CFStringCreateWithCharacters(NULL, (UniChar *)s.unicode(), s.length());
       
   455             options.location.h = (parent->x() + (parent->width() / 2)) - (w / 2);
       
   456             options.location.v = (parent->y() + (parent->height() / 2)) - (h / 2);
       
   457 
       
   458             QRect r = QApplication::desktop()->screenGeometry(
       
   459                 QApplication::desktop()->screenNumber(parent));
       
   460             if(options.location.h + w > r.right())
       
   461                 options.location.h -= (options.location.h + w) - r.right() + 10;
       
   462             if(options.location.v + h > r.bottom())
       
   463                 options.location.v -= (options.location.v + h) - r.bottom() + 10;
       
   464         }
       
   465     } else if(QWidget *p = qApp->mainWidget()) {
       
   466         static int last_screen = -1;
       
   467         int scr = QApplication::desktop()->screenNumber(p);
       
   468         if(last_screen != scr) {
       
   469             QRect r = QApplication::desktop()->screenGeometry(scr);
       
   470             options.location.h = (r.x() + (r.width() / 2)) - (w / 2);
       
   471             options.location.v = (r.y() + (r.height() / 2)) - (h / 2);
       
   472         }
       
   473     }
       
   474 
       
   475     QList<qt_mac_filter_name*> filts = makeFiltersList(filter);
       
   476     qt_mac_nav_filter_type t;
       
   477     t.index = 0;
       
   478     t.filts = &filts;
       
   479     if(filts.count() > 1) {
       
   480         int i = 0;
       
   481         CFStringRef *arr = (CFStringRef *)malloc(sizeof(CFStringRef) * filts.count());
       
   482         for (QList<qt_mac_filter_name*>::Iterator it = filts.begin(); it != filts.end(); ++it) {
       
   483             QString rg = (*it)->description;
       
   484             arr[i++] = CFStringCreateWithCharacters(NULL, (UniChar *)rg.unicode(), rg.length());
       
   485         }
       
   486         options.popupExtension = CFArrayCreate(NULL, (const void **)arr, filts.count(), NULL);
       
   487     }
       
   488 
       
   489     NavDialogRef dlg;
       
   490     if(NavCreatePutFileDialog(&options, 'cute', kNavGenericSignature, make_navProcUPP(),
       
   491                               (void *) (filts.isEmpty() ? NULL : &t), &dlg)) {
       
   492         qDebug("Shouldn't happen %s:%d", __FILE__, __LINE__);
       
   493         return retstr;
       
   494     }
       
   495     if (!workingDir.isEmpty()) {
       
   496         FSRef fsref;
       
   497         if (qt_mac_create_fsref(workingDir, &fsref) == noErr) {
       
   498             AEDesc desc;
       
   499             if (AECreateDesc(typeFSRef, &fsref, sizeof(FSRef), &desc) == noErr)
       
   500                 NavCustomControl(dlg, kNavCtlSetLocation, (void*)&desc);
       
   501         }
       
   502     }
       
   503     NavDialogRun(dlg);
       
   504     if (selectedFilter) {
       
   505         NavMenuItemSpec navSpec;
       
   506         bzero(&navSpec, sizeof(NavMenuItemSpec));
       
   507         qt_mac_filter_name *sel_filt_name = makeFiltersList(*selectedFilter).at(0);
       
   508         for (int i = 0; i < filts.count(); ++i) {
       
   509             const qt_mac_filter_name *filter = filts.at(i);
       
   510             if (sel_filt_name->description == filter->description
       
   511                     && sel_filt_name->regxp == filter->regxp
       
   512                     && sel_filt_name->filter == filter->filter) {
       
   513                 navSpec.menuType = i;
       
   514                 break;
       
   515             }
       
   516         }
       
   517         NavCustomControl(dlg, kNavCtlSelectCustomType, &navSpec);
       
   518     }
       
   519     if(options.modality == kWindowModalityWindowModal) { //simulate modality
       
   520         QWidget modal_widg(parent, __FILE__ "__modal_dlg",
       
   521                            Qt::WType_TopLevel | Qt::WStyle_Customize | Qt::WStyle_DialogBorder);
       
   522         modal_widg.createWinId();
       
   523         QApplicationPrivate::enterModal(&modal_widg);
       
   524         while(g_nav_blocking)
       
   525             qApp->processEvents(QEventLoop::WaitForMoreEvents);
       
   526         QApplicationPrivate::leaveModal(&modal_widg);
       
   527     }
       
   528 
       
   529     if(NavDialogGetUserAction(dlg) != kNavUserActionSaveAs) {
       
   530         NavDialogDispose(dlg);
       
   531         return retstr;
       
   532     }
       
   533     NavReplyRecord ret;
       
   534     NavDialogGetReply(dlg, &ret);
       
   535     NavDialogDispose(dlg);
       
   536 
       
   537     long count;
       
   538     err = AECountItems(&(ret.selection), &count);
       
   539     if(!ret.validRecord || err != noErr || !count) {
       
   540         NavDisposeReply(&ret);
       
   541         return retstr;
       
   542     }
       
   543 
       
   544     AEKeyword        keyword;
       
   545     DescType    type;
       
   546     Size        size;
       
   547     FSRef ref;
       
   548     err = AEGetNthPtr(&(ret.selection), 1, typeFSRef, &keyword,
       
   549                       &type, &ref, sizeof(ref), &size);
       
   550     if(err == noErr) {
       
   551         if(!str_buffer) {
       
   552             qAddPostRoutine(cleanup_str_buffer);
       
   553             str_buffer = (UInt8 *)malloc(1024);
       
   554         }
       
   555         FSRefMakePath(&ref, str_buffer, 1024);
       
   556         retstr = QString::fromUtf8((const char *)str_buffer);
       
   557         //now filename
       
   558         CFStringGetCString(ret.saveFileName, (char *)str_buffer, 1024, kCFStringEncodingUTF8);
       
   559         retstr += QLatin1Char('/') + QString::fromUtf8((const char *)str_buffer);
       
   560     }
       
   561     NavDisposeReply(&ret);
       
   562     if(selectedFilter)
       
   563         *selectedFilter = filts.at(t.index)->filter;
       
   564     while (!filts.isEmpty())
       
   565         delete filts.takeFirst();
       
   566     return retstr;
       
   567 }
       
   568 
       
   569 #endif // QT_MAC_USE_COCOA
       
   570 
       
   571 QT_END_NAMESPACE
       
   572 
       
   573 #endif