View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002219 | Scribus | Internal | public | 2005-07-10 20:52 | 2005-11-05 13:07 |
Reporter | jghali | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | Windows | OS | Windows | OS Version | 2000 SP4 |
Product Version | 1.3.0cvs | ||||
Fixed in Version | 1.3.2cvs | ||||
Summary | 0002219: On Win32, add the ability to locate special directories and sytem fonts folder | ||||
Description | The patch add static methods ScPaths to get common folder( "Application Data", "My Documents") and special directories ( system font folder ...). Add also some code to ScFonts to get some fonts in all case... | ||||
Tags | No tags attached. | ||||
Patch | |||||
2005-07-10 20:52
|
scpaths_spec_dirs_13x.diff (4,201 bytes)
Index: scfonts.cpp =================================================================== RCS file: /cvs/Scribus/scribus/scfonts.cpp,v retrieving revision 1.15.2.23 diff -u -r1.15.2.23 scfonts.cpp --- scfonts.cpp 8 Jul 2005 17:31:36 -0000 1.15.2.23 +++ scfonts.cpp 10 Jul 2005 22:26:40 -0000 @@ -40,6 +40,10 @@ #include <fontconfig/fontconfig.h> #endif +#ifdef _WIN32 +#include "scpaths.h" +#endif + #include "util.h" #include FT_INTERNAL_STREAM_H @@ -910,6 +914,10 @@ for(QStrListIterator fpi(FontPath) ; fpi.current() ; ++fpi) AddScalableFonts(fpi.current()); AddFontconfigFonts(); +#ifdef _WIN32 + if( FontPath.count() == 0 ) + AddScalableFonts( ScPaths::getSystemFontDir(false) ); +#endif #else // if FreeType thinks we are on Mac, let it search the default paths #if FT_MACINTOSH @@ -917,6 +925,8 @@ AddScalableFonts("/Library/Fonts/"); AddScalableFonts("/Network/Library/Fonts/"); AddScalableFonts("/System/Library/Fonts/"); +#elif defined(_WIN32) + AddScalableFonts( ScPaths::getSystemFontDir(false) ); #endif // on X11 look there: #ifdef Q_WS_X11 Index: scpaths.cpp =================================================================== RCS file: /cvs/Scribus/scribus/Attic/scpaths.cpp,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 scpaths.cpp --- scpaths.cpp 6 Jul 2005 20:07:15 -0000 1.1.2.5 +++ scpaths.cpp 10 Jul 2005 22:35:46 -0000 @@ -10,6 +10,11 @@ #include <CoreFoundation/CoreFoundation.h> #endif +#ifdef _WIN32 +#include <windows.h> +#include <shlobj.h> +#endif + // Init the singleton's "self" address to NULL ScPaths* ScPaths::m_instance = NULL; @@ -90,7 +95,17 @@ qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir)); qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":"))); */ -#endif // defined(BUILD_MAC_BUNDLE) +#elif defined( _WIN32 ) + QString appPath = qApp->applicationDirPath(); + m_shareDir = strdup(QString("%1/share/").arg(appPath)); + m_docDir = strdup(QString("%1/share/doc/").arg(appPath)); + m_iconDir = strdup(QString("%1/share/icons/").arg(appPath)); + m_sampleScriptDir = strdup(QString("%1/share/samples/").arg(appPath)); + m_scriptDir = strdup(QString("%1/share/scripts/").arg(appPath)); + m_templateDir = strdup(QString("%1/share/templates/").arg(appPath)); + m_libDir = strdup(QString("%1/libs/").arg(appPath)); + m_pluginDir = strdup(QString("%1/plugins/").arg(appPath)); +#endif } ScPaths::~ScPaths() {}; @@ -134,3 +149,34 @@ { return m_shareDir; } + +#if defined (_WIN32) + +QString ScPaths::getAppDataDir(bool useSlashs) +{ + return getSpecialDir(CSIDL_APPDATA, useSlashs); +} + +QString ScPaths::getMyDocumentDir(bool useSlashs) +{ + return getSpecialDir(CSIDL_PERSONAL, useSlashs); +} + +QString ScPaths::getSystemFontDir(bool useSlashs) +{ + return getSpecialDir(CSIDL_FONTS, useSlashs); +} + +QString ScPaths::getSpecialDir(int folder, bool useSlashs) +{ + char dir[256]; + SHGetSpecialFolderPath(NULL, dir, folder , false); + QString qstr(dir); + if( !qstr.endsWith("\\") ) + qstr += "\\"; + if(useSlashs) + qstr.replace( '\\', '/' ); + return qstr; +} + +#endif Index: scpaths.h =================================================================== RCS file: /cvs/Scribus/scribus/Attic/scpaths.h,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 scpaths.h --- scpaths.h 6 Jul 2005 20:07:16 -0000 1.1.2.2 +++ scpaths.h 10 Jul 2005 22:36:16 -0000 @@ -36,6 +36,17 @@ /** @brief Return path to the Scribus share directory */ const QString& shareDir() const; +#if defined (_WIN32) + /** @brief Return path to Application Data directory*/ + static QString getAppDataDir(bool useSlashs = true); + /** @brief Return path to My Documents directory*/ + static QString getMyDocumentDir(bool useSlashs = true); + /** @brief Return path to Windows Font directory*/ + static QString getSystemFontDir(bool useSlashs = true); + /** @brief Return path to a special directory*/ + static QString getSpecialDir(int folder, bool useSlashs = true); +#endif + protected: /** @brief Constructor. Use ScPaths::instance() instead. */ ScPaths(); |
|
I just had a look over that patch. I'm not too sure I'm comfortable making the win32-specific path features public. We should probably abstract it to something that can make sense on other platforms, eg userDocumentDir(...) which can return the My Docs folder path on win32, /Users/$USERNAME/Documents on Mac OS X, etc. I would very strongly prefer not to #ifdef any public API in scpaths. I think Scribus uses preprocessor macros way too much already. A public methods that only exist on some platforms is likely to make it much too easy to write code that works for one platform but breaks horribly on another. QString getSystemFontDir() can probably become QStringList getSystemFontDirs(...) and handle the Mac OS X font paths too. getSpecialDir should probably be protected. It might also be better implemented as a stub that asserts false rather than #ifdef'd out on non win32 platforms. That lets us keep scconfig.h and conditional compilation out of the scpaths header. getMyDocumentsDir I already covered. I'm not too sure about getApplicationDataDir . There's no real analogue for that on other platforms. What sort of things were you thinking of using it for? Prefs files etc? If so, maybe we need to work in a more general way of locating prefs files so that we can return $HOME/.scribus on *nix, %APPDATADIR%/Scribus (or whatever) on win32, etc. Am I making sense? |
|
"Application Data" will be used to store prefs file. So a general way of locating prefs files make sense indeed. I will modify the whole patch tonight to take your views into account. |
2005-07-11 14:00
|
scpaths_spec_dirs_13x_v2.diff (6,649 bytes)
Index: scfonts.cpp =================================================================== RCS file: /cvs/Scribus/scribus/scfonts.cpp,v retrieving revision 1.15.2.23 diff -u -r1.15.2.23 scfonts.cpp --- scfonts.cpp 8 Jul 2005 17:31:36 -0000 1.15.2.23 +++ scfonts.cpp 11 Jul 2005 15:47:59 -0000 @@ -40,6 +40,7 @@ #include <fontconfig/fontconfig.h> #endif +#include "scpaths.h" #include "util.h" #include FT_INTERNAL_STREAM_H @@ -486,12 +487,15 @@ FT_Library library = NULL; QString pathfile; bool error; - error = FT_Init_FreeType( &library ); + error = FT_Init_FreeType( &library ); QDir d(path, "*", QDir::Name, QDir::Dirs | QDir::Files | QDir::Readable); if ((d.exists()) && (d.count() != 0)) { for (uint dc = 0; dc < d.count(); ++dc) { + if( d[dc] == "." || d[dc] == ".." ) // Necessary on Windows + continue; + QFileInfo fi(path+d[dc]); if (!fi.exists()) // Sanity check for broken Symlinks continue; @@ -910,13 +914,18 @@ for(QStrListIterator fpi(FontPath) ; fpi.current() ; ++fpi) AddScalableFonts(fpi.current()); AddFontconfigFonts(); + if( FontPath.count() == 0 ) // Search the default paths + { + QStringList ftDirs = ScPaths::getSystemFontDirs(); + for(unsigned int i = 0; i < ftDirs.count(); i++) + AddScalableFonts( ftDirs[i] ); + } #else -// if FreeType thinks we are on Mac, let it search the default paths -#if FT_MACINTOSH - AddScalableFonts(QDir::homeDirPath() + "/Library/Fonts/"); - AddScalableFonts("/Library/Fonts/"); - AddScalableFonts("/Network/Library/Fonts/"); - AddScalableFonts("/System/Library/Fonts/"); +// if FreeType thinks we are on Mac or Win32, let it search the default paths +#if FT_MACINTOSH || defined(_WIN32) + QStringList ftDirs = ScPaths::getSystemFontDirs(); + for(int i = 0; i < ftDirs.count(); i++) + AddScalableFonts( ftDirs[i] ); #endif // on X11 look there: #ifdef Q_WS_X11 Index: scpaths.cpp =================================================================== RCS file: /cvs/Scribus/scribus/Attic/scpaths.cpp,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 scpaths.cpp --- scpaths.cpp 6 Jul 2005 20:07:15 -0000 1.1.2.5 +++ scpaths.cpp 11 Jul 2005 15:18:59 -0000 @@ -1,15 +1,22 @@ #include "scpaths.h" #include <qapplication.h> +#include <qdir.h> #include "scconfig.h" - // On Qt/Mac we need CoreFoundation to discover the location // of the app bundle. #ifdef BUILD_MAC_BUNDLE #include <CoreFoundation/CoreFoundation.h> #endif +#ifdef _WIN32 +#include <windows.h> +#include <shlobj.h> +#else +#include <assert.h> +#endif + // Init the singleton's "self" address to NULL ScPaths* ScPaths::m_instance = NULL; @@ -77,6 +84,8 @@ m_templateDir = strdup(QString("%1/Contents/share/scribus/templates/").arg(pathPtr)); m_libDir = strdup(QString("%1/Contents/lib/scribus/").arg(pathPtr)); m_pluginDir = strdup(QString("%1/Contents/lib/scribus/plugins/").arg(pathPtr)); + m_userDocDir = QDir::homeDirPath() + "/Desktop/"; + m_prefDir = QDir::homeDirPath() + "/.scribus/"; QApplication::setLibraryPaths(QString("%1/Contents/lib/qtplugins/").arg(pathPtr)); CFRelease(pluginRef); CFRelease(macPath); @@ -90,7 +99,22 @@ qDebug(QString("scpaths: plugin dir=%1").arg(m_pluginDir)); qDebug(QString("scpaths: qtplugins=%1").arg(QApplication::libraryPaths().join(":"))); */ -#endif // defined(BUILD_MAC_BUNDLE) +#elif defined(_WIN32) + QString appPath = qApp->applicationDirPath(); + m_shareDir = strdup(QString("%1/share/").arg(appPath)); + m_docDir = strdup(QString("%1/share/doc/").arg(appPath)); + m_iconDir = strdup(QString("%1/share/icons/").arg(appPath)); + m_sampleScriptDir = strdup(QString("%1/share/samples/").arg(appPath)); + m_scriptDir = strdup(QString("%1/share/scripts/").arg(appPath)); + m_templateDir = strdup(QString("%1/share/templates/").arg(appPath)); + m_libDir = strdup(QString("%1/libs/").arg(appPath)); + m_pluginDir = strdup(QString("%1/plugins/").arg(appPath)); + m_userDocDir = getSpecialDir(CSIDL_PERSONAL); + m_prefDir = getSpecialDir(CSIDL_APPDATA) + "Scribus/"; +#else + m_userDocDir = QDir::homeDirPath(); + m_prefDir = QDir::homeDirPath() + "/.scribus/"; +#endif } ScPaths::~ScPaths() {}; @@ -134,3 +158,43 @@ { return m_shareDir; } + +const QString& ScPaths::userDocumentDir() const +{ + return m_userDocDir; +} + +const QString& ScPaths::preferenceDir() const +{ + return m_prefDir; +} + +QStringList ScPaths::getSystemFontDirs(void) +{ + QStringList fontDirs; +#ifdef BUILD_MAC_BUNDLE + fontDirs.append(QDir::homeDirPath() + "/Library/Fonts/"); + fontDirs.append("/Library/Fonts/"); + fontDirs.append("/Network/Library/Fonts/"); + fontDirs.append("/System/Library/Fonts/"); +#else if defined(_WIN32) + fontDirs.append( getSpecialDir(CSIDL_FONTS) ); +#endif + return fontDirs; +} + +QString ScPaths::getSpecialDir(int folder) +{ + QString qstr; +#if defined( _WIN32 ) + char dir[256]; + SHGetSpecialFolderPath(NULL, dir, folder , false); + qstr = dir; + if( !qstr.endsWith("\\") ) + qstr += "\\"; + qstr.replace( '\\', '/' ); +#else + assert(false); +#endif + return qstr; +} Index: scpaths.h =================================================================== RCS file: /cvs/Scribus/scribus/Attic/scpaths.h,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 scpaths.h --- scpaths.h 6 Jul 2005 20:07:16 -0000 1.1.2.2 +++ scpaths.h 11 Jul 2005 13:47:41 -0000 @@ -2,6 +2,7 @@ #define SCPATHS_H #include "qstring.h" +#include "qstringlist.h" class ScPaths { @@ -35,6 +36,13 @@ const QString& templateDir() const; /** @brief Return path to the Scribus share directory */ const QString& shareDir() const; + /** @brief Return path to the user documents directory */ + const QString& userDocumentDir() const; + /** @brief Return path to the preference directory */ + const QString& preferenceDir() const; + + /** @brief Return paths to system font directories*/ + static QStringList getSystemFontDirs(void); protected: /** @brief Constructor. Use ScPaths::instance() instead. */ @@ -42,6 +50,9 @@ /** @brief Destructor. Use ScPaths::destroy() instead. */ ~ScPaths(); + /** @brief Return path to a special directory, should be used only on Windows*/ + static QString getSpecialDir(int folder); + /** @brief Pointer to existing instance of ScPaths, if any. */ static ScPaths* m_instance; @@ -54,5 +65,7 @@ QString m_scriptDir; QString m_templateDir; QString m_shareDir; + QString m_userDocDir; + QString m_prefDir; }; #endif |
|
A new patch has been uploaded. Andreas should test it as some changes have been made in mac related sections. Btw, some mac related section are now win32 related section also... |
|
Sorry I didn't respond earlier to this. I didn't get the notification mails due to some trouble with bugs.scribus.net . Unfortunately I'm a bit swamped right now but will be sure to check them out ASAP. |
|
Reminder sent to: avox avox, jghali suggested you might want to check this patch out for its Mac OS X impact. Look sane? |
|
>> Unfortunately I'm a bit swamped right now. Take your time... I'm reading Metro specifications... Another (future) way of allowing printing to work on Windows... |
|
Hi I've read over that patch. I have a few comments and suggestions. I'm happy to implement these myself, if you think they're reasonable. First, I'm not too sure that the win32 font dir(s) should be omitted from searching if the user has specified any extra font paths. It should be searched anyway. We can always have a pref later to suppress searching of system font paths if that is needed. So ... I'd remove the block beginning with the: if( FontPath.count() == 0 ) near line 910, and remove the conditional compilation from the block: +#if FT_MACINTOSH || defined(_WIN32) in favour of moving the system font path selection into scpaths. I'd like to entirely remove X11 font path searching in favour of fontconfig, too. Also, I think userDocDir should come from prefs, but be initialized to a sensible platform default. I'll take care of that. I'd prefer to use Q_ASSERT(false) than assert(false) in getSpecialFolder. Q_ASSERT can be compiled out entirely, made fatal, or left as its default - a warning. It also means we don't need <assert.h> . Again, I'll tweak that. If you think those alterations make sense, I'll get this into CVS soon. |
|
Those alterations make sense :-) |
|
Sorry I haven't got to this yet. Study and work are making much coding hard. It hasn't been forgotten. |
|
I have splitted the patch as ScPaths modifications are getting needed for further work. Issue 0002490 restrict modifications to ScPaths.h and ScPaths.cpp. |
|
The patch provided by 0002794 bring modifications needed to scfonts.cpp. Issue can be closed. |
Date Modified | Username | Field | Change |
---|---|---|---|
2005-07-10 20:52 | jghali | New Issue | |
2005-07-10 20:52 | jghali | File Added: scpaths_spec_dirs_13x.diff | |
2005-07-11 10:23 |
|
Status | new => assigned |
2005-07-11 10:23 |
|
Assigned To | => ringerc |
2005-07-11 10:32 |
|
Note Added: 0005504 | |
2005-07-11 10:44 | jghali | Note Added: 0005506 | |
2005-07-11 14:00 | jghali | File Added: scpaths_spec_dirs_13x_v2.diff | |
2005-07-11 14:10 | jghali | Note Added: 0005521 | |
2005-07-13 15:07 |
|
Note Added: 0005564 | |
2005-07-13 15:08 |
|
Note Added: 0005565 | |
2005-07-13 18:34 | jghali | Note Added: 0005568 | |
2005-07-14 02:41 |
|
Note Added: 0005580 | |
2005-07-14 06:14 | jghali | Note Added: 0005581 | |
2005-07-15 07:37 |
|
Relationship added | related to 0000015 |
2005-07-15 07:41 |
|
Relationship replaced | child of 0000015 |
2005-08-13 07:22 |
|
Note Added: 0006104 | |
2005-08-26 23:07 | jghali | Relationship added | related to 0002490 |
2005-08-26 23:11 | jghali | Note Added: 0006252 | |
2005-11-05 13:01 | jghali | Relationship added | related to 0002794 |
2005-11-05 13:04 | jghali | Note Added: 0007333 | |
2005-11-05 13:06 | jghali | Status | assigned => resolved |
2005-11-05 13:06 | jghali | Fixed in Version | => 1.3.2cvs |
2005-11-05 13:06 | jghali | Resolution | open => fixed |
2005-11-05 13:07 | cbradney | Status | resolved => closed |