@@ -47,6 +47,8 @@ class CPtr
4747 inline operator T*() const { return d; }
4848 inline T** operator &() { return &d; }
4949};
50+ #elif defined(Q_OS_MAC)
51+ #include < sys/xattr.h>
5052#endif
5153
5254#include < array>
@@ -61,7 +63,7 @@ QString FileDialog::createNewFileName(const QString &file, bool signature, QWidg
6163 const QFileInfo f (normalized (file));
6264 QString dir = defaultDir.isEmpty () ? f.absolutePath () : defaultDir;
6365 QString fileName = QDir::toNativeSeparators (dir + QDir::separator () + f.completeBaseName () + extension);
64- #ifndef Q_OS_OSX
66+ #ifndef Q_OS_MACOS
6567 // macOS App Sandbox restricts the rights of the application to write to the filesystem outside of
6668 // app sandbox; user must explicitly give permission to write data to the specific folders.
6769 if (!QFile::exists (fileName))
@@ -107,23 +109,6 @@ bool FileDialog::fileIsWritable( const QString &filename )
107109 return result;
108110}
109111
110- int FileDialog::fileZone (const QString &path)
111- {
112- #ifdef Q_OS_WIN
113- CPtr<IZoneIdentifier> spzi;
114- CPtr<IPersistFile> spf;
115- DWORD dwZone = 0 ;
116- if (SUCCEEDED (CoCreateInstance (CLSID_PersistentZoneIdentifier, nullptr , CLSCTX_INPROC, IID_PPV_ARGS (&spzi))) &&
117- SUCCEEDED (spzi->QueryInterface (&spf)) &&
118- SUCCEEDED (spf->Load (LPCWSTR (QDir::toNativeSeparators (path).utf16 ()), STGM_READ)) &&
119- SUCCEEDED (spzi->GetId (&dwZone)))
120- return int (dwZone);
121- #else
122- Q_UNUSED (path)
123- #endif
124- return -1 ;
125- }
126-
127112bool FileDialog::isSignedPDF (const QString &path)
128113{
129114 if (!path.endsWith (QLatin1String (" pdf" ), Qt::CaseInsensitive))
@@ -136,25 +121,33 @@ bool FileDialog::isSignedPDF(const QString &path)
136121 return std::any_of (list.begin (), list.end (), [&blob](const char *token) { return blob.indexOf (token) > 0 ; });
137122}
138123
139- void FileDialog::setFileZone (const QString &path, int zone )
124+ void FileDialog::setFileZone (const QString &target, const QString &source )
140125{
141- if (zone < 0 )
142- return ;
143126#ifdef Q_OS_WIN
144127 CPtr<IZoneIdentifier> spzi;
145128 CPtr<IPersistFile> spf;
146- if (SUCCEEDED (CoCreateInstance (CLSID_PersistentZoneIdentifier, nullptr , CLSCTX_INPROC, IID_PPV_ARGS (&spzi))) &&
147- SUCCEEDED (spzi->SetId (zone)) &&
148- SUCCEEDED (spzi->QueryInterface (&spf)))
149- spf->Save (LPCWSTR (QDir::toNativeSeparators (path).utf16 ()), TRUE );
129+ if (SUCCEEDED (CoCreateInstance (CLSID_PersistentZoneIdentifier, nullptr , CLSCTX_INPROC_SERVER, IID_PPV_ARGS (&spzi))) &&
130+ SUCCEEDED (spzi->QueryInterface (&spf)) &&
131+ SUCCEEDED (spf->Load (LPCWSTR (QDir::toNativeSeparators (source).utf16 ()), STGM_READ)))
132+ spf->Save (LPCWSTR (QDir::toNativeSeparators (target).utf16 ()), TRUE );
133+ #elif defined(Q_OS_MACOS)
134+ QByteArray p = QFile::encodeName (source);
135+ ssize_t n = getxattr (p.constData (), " com.apple.quarantine" , nullptr , 0 , 0 , 0 );
136+ if (n <= 0 )
137+ return ;
138+ QByteArray value (int (n), Qt::Uninitialized);
139+ n = getxattr (p.constData (), " com.apple.quarantine" , value.data (), value.size (), 0 , 0 );
140+ if (n > 0 )
141+ setxattr (QFile::encodeName (target).constData (), " com.apple.quarantine" , value.constData (), size_t (n), 0 , 0 );
150142#else
151- Q_UNUSED (path)
143+ Q_UNUSED (target)
144+ Q_UNUSED (source)
152145#endif
153146}
154147
155148void FileDialog::setReadOnly (const QString &path, bool readonly)
156149{
157- #if defined( Q_OS_WIN)
150+ #ifdef Q_OS_WIN
158151 ::SetFileAttributesW (LPCWSTR(path.utf16()), readonly ? FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL);
159152#else
160153 QFile::setPermissions (path, QFile::Permissions (QFile::Permission::ReadOwner)
@@ -164,7 +157,7 @@ void FileDialog::setReadOnly(const QString &path, bool readonly)
164157
165158QString FileDialog::getDir ( const QString &dir )
166159{
167- #ifdef Q_OS_OSX
160+ #ifdef Q_OS_MACOS
168161 Q_UNUSED (dir)
169162 QString path = QSettings ().value (QStringLiteral (" NSNavLastRootDirectory" )).toString ();
170163 path.replace (' ~' , QDir::homePath ());
@@ -266,14 +259,30 @@ QString FileDialog::getExistingDirectory( QWidget *parent, const QString &captio
266259 return result ( res );
267260}
268261
269- QString FileDialog::getSaveFileName ( QWidget *parent, const QString &caption,
270- const QString &dir, const QString &filter, QString *selectedFilter, Options options )
262+ QString FileDialog::getSaveFileName (QWidget *parent, const QString &caption, const QString &filename, QString filter)
271263{
264+ if (!filter.isEmpty ())
265+ filter.clear ();
266+ else if (filename.endsWith (QLatin1String (" .adoc" ), Qt::CaseInsensitive))
267+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.adoc" ));
268+ else if (filename.endsWith (QLatin1String (" .asice" ), Qt::CaseInsensitive) ||
269+ filename.endsWith (QLatin1String (" .sce" ), Qt::CaseInsensitive))
270+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.asice *.sce" ));
271+ else if (filename.endsWith (QLatin1String (" .asics" ), Qt::CaseInsensitive) ||
272+ filename.endsWith (QLatin1String (" .scs" ), Qt::CaseInsensitive))
273+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.asics *.scs" ));
274+ else if (filename.endsWith (QLatin1String (" .bdoc" ), Qt::CaseInsensitive))
275+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.bdoc" ));
276+ else if (filename.endsWith (QLatin1String (" .cdoc" ), Qt::CaseInsensitive))
277+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.cdoc" ));
278+ else if (filename.endsWith (QLatin1String (" .cdoc2" ), Qt::CaseInsensitive))
279+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.cdoc2" ));
280+ else if (filename.endsWith (QLatin1String (" .edoc" ), Qt::CaseInsensitive))
281+ filter = tr (" Documents (%1)" ).arg (QLatin1String (" *.edoc" ));
272282 QString file;
273283 while ( true )
274284 {
275- file = QFileDialog::getSaveFileName (parent,
276- caption, normalized (dir), filter, selectedFilter, options);
285+ file = QFileDialog::getSaveFileName (parent, caption, normalized (filename), filter);
277286 if ( !file.isEmpty () && !fileIsWritable ( file ) )
278287 {
279288 WarningDialog::show (parent, tr ( " You don't have sufficient privileges to write this file into folder %1" ).arg ( file ));
@@ -301,7 +310,7 @@ QString FileDialog::normalized(const QString &data)
301310
302311QString FileDialog::result ( const QString &str )
303312{
304- #ifndef Q_OS_OSX
313+ #ifndef Q_OS_MACOS
305314 if (!str.isEmpty ())
306315 Settings::LAST_PATH = QFileInfo (str).absolutePath ();
307316#else
@@ -322,7 +331,7 @@ QString FileDialog::tempPath(const QString &file)
322331{
323332 QDir tmp = QDir::temp ();
324333 if (!tmp.exists (file))
325- return tmp.path () + " / " + file;
334+ return tmp.path () + ' / ' + file;
326335 QFileInfo info (file);
327336 int i = 0 ;
328337 while (tmp.exists (QStringLiteral (" %1_%2.%3" ).arg (info.baseName ()).arg (i).arg (info.suffix ())))
@@ -334,7 +343,7 @@ QString FileDialog::safeName(const QString &file)
334343{
335344 QFileInfo info (file);
336345 QString filename = info.fileName ();
337- #if defined( Q_OS_WIN)
346+ #ifdef Q_OS_WIN
338347 static const QStringList disabled { " CON" , " PRN" , " AUX" , " NUL" ,
339348 " COM1" , " COM2" , " COM3" , " COM4" , " COM5" , " COM6" , " COM7" , " COM8" , " COM9" ,
340349 " LPT1" , " LPT2" , " LPT3" , " LPT4" , " LPT5" , " LPT6" , " LPT7" , " LPT8" , " LPT9" };
0 commit comments