mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Close #93 Default output folder / Improve Portable App usability
- allow setting a database as default - Strip xca-app-folder from database and export filenames. This allows renaming/moving the portable app and open the default DB and use the working directory inside the folder - Remember database history and configured language
This commit is contained in:
parent
23a737bbfa
commit
580a2fae2b
77
lib/func.cpp
77
lib/func.cpp
@ -30,6 +30,7 @@
|
||||
#endif
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QStringList>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@ -89,9 +90,9 @@ int portable_app()
|
||||
QString getPrefix()
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
static char inst_dir[100] = "";
|
||||
static char inst_dir[512] = "";
|
||||
char *p;
|
||||
ULONG dwLength = 100;
|
||||
ULONG dwLength = sizeof inst_dir;
|
||||
HKEY hKey;
|
||||
|
||||
if (inst_dir[0] != '\0') {
|
||||
@ -115,7 +116,7 @@ QString getPrefix()
|
||||
XCA_WARN("Registry Key: 'HKEY_LOCAL_MACHINE\\Software\\xca' not found");
|
||||
return QString(inst_dir);
|
||||
}
|
||||
if (RegQueryValueEx(hKey, "Install_Dir", NULL, NULL,
|
||||
if (RegQueryValueEx(hKey, "Install_Dir64", NULL, NULL,
|
||||
(unsigned char *)inst_dir, &dwLength) != ERROR_SUCCESS)
|
||||
{
|
||||
XCA_WARN("Registry Key: 'HKEY_LOCAL_MACHINE->Software->xca->Install_Dir' not found");
|
||||
@ -138,38 +139,56 @@ QString getPrefix()
|
||||
|
||||
}
|
||||
|
||||
QString getHomeDir()
|
||||
{
|
||||
QString hd;
|
||||
#if defined(Q_OS_WIN32)
|
||||
static QString specialFolder(int csidl)
|
||||
{
|
||||
LPITEMIDLIST pidl = NULL;
|
||||
TCHAR buf[255] = "";
|
||||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl))) {
|
||||
|
||||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, csidl, &pidl)))
|
||||
SHGetPathFromIDList(pidl, buf);
|
||||
}
|
||||
hd = buf;
|
||||
#else
|
||||
hd = QDir::homePath();
|
||||
|
||||
return QDir::toNativeSeparators(buf);
|
||||
}
|
||||
#endif
|
||||
return hd;
|
||||
|
||||
QString getHomeDir()
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
return portable_app() ? getPrefix() : specialFolder(CSIDL_PERSONAL);
|
||||
#else
|
||||
return QDir::homePath();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* For portable APP remove leading file name if it is
|
||||
* the app directory.
|
||||
*/
|
||||
QString relativePath(QString path)
|
||||
{
|
||||
QFileInfo fi_path(path);
|
||||
QFileInfo fi_home(getHomeDir());
|
||||
|
||||
QString prefix = QDir::toNativeSeparators(fi_home.canonicalFilePath());
|
||||
path = QDir::toNativeSeparators(fi_path.canonicalFilePath());
|
||||
|
||||
if (portable_app()) {
|
||||
if (path.startsWith(prefix))
|
||||
path = path.mid(prefix.length()+1);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
QString getLibDir()
|
||||
{
|
||||
QString hd;
|
||||
#if defined(Q_OS_WIN32)
|
||||
LPITEMIDLIST pidl = NULL;
|
||||
TCHAR buf[255] = "";
|
||||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_SYSTEM, &pidl))) {
|
||||
SHGetPathFromIDList(pidl, buf);
|
||||
}
|
||||
hd = buf;
|
||||
return specialFolder(CSIDL_SYSTEM);
|
||||
#else
|
||||
QString ulib = "/usr/lib/";
|
||||
QString lib = "/lib/";
|
||||
QString multi;
|
||||
QString hd = ulib;
|
||||
|
||||
hd = ulib;
|
||||
QFile f(ulib + "pkg-config.multiarch");
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
QTextStream in(&f);
|
||||
@ -192,8 +211,8 @@ QString getLibDir()
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return QDir::toNativeSeparators(hd);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString getDocDir()
|
||||
@ -213,14 +232,8 @@ QString getUserSettingsDir()
|
||||
{
|
||||
QString rv;
|
||||
#if defined(Q_OS_WIN32)
|
||||
LPITEMIDLIST pidl = NULL;
|
||||
TCHAR buf[255] = "";
|
||||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl))) {
|
||||
SHGetPathFromIDList(pidl, buf);
|
||||
}
|
||||
rv = buf;
|
||||
rv += QDir::separator();
|
||||
rv += "xca";
|
||||
rv = portable_app() ? getPrefix() + "/settings" :
|
||||
specialFolder(CSIDL_APPDATA) + "/xca";
|
||||
#elif defined(Q_OS_MAC)
|
||||
#if QT_VERSION < 0x050000
|
||||
rv = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
@ -233,11 +246,9 @@ QString getUserSettingsDir()
|
||||
QCoreApplication::applicationName();
|
||||
#endif
|
||||
#else
|
||||
rv = QDir::homePath();
|
||||
rv += QDir::separator();
|
||||
rv += ".xca";
|
||||
rv = QDir::homePath() + "/.xca";
|
||||
#endif
|
||||
return rv;
|
||||
return QDir::toNativeSeparators(rv);
|
||||
}
|
||||
|
||||
// Qt's open and save dialogs result in some undesirable quirks.
|
||||
|
||||
@ -29,6 +29,7 @@ QString getHomeDir();
|
||||
QString getLibDir();
|
||||
QString getDocDir();
|
||||
QString getUserSettingsDir();
|
||||
QString relativePath(QString path);
|
||||
QString getFullFilename(const QString &filename, const QString &selectedFilter);
|
||||
const QStringList getLibExtensions();
|
||||
QString hostId();
|
||||
|
||||
@ -142,9 +142,6 @@ void XCA_application::switchLanguage(QAction* a)
|
||||
QLocale lang = a->data().toLocale();
|
||||
setupLanguage(lang);
|
||||
|
||||
if (portable_app())
|
||||
return;
|
||||
|
||||
QFile file(defaultlang());
|
||||
|
||||
if (lang == QLocale::system()) {
|
||||
|
||||
@ -30,7 +30,8 @@ settings::settings()
|
||||
defaul["mandatory_dn"] = "";
|
||||
defaul["explicit_dn"] = "C,ST,L,O,OU,CN,emailAddress";
|
||||
defaul["string_opt"] = "MASK:0x2002";
|
||||
defaul["workingdir"] = QDir::toNativeSeparators(QDir::currentPath());
|
||||
defaul["workingdir"] = QDir::toNativeSeparators(portable_app() ?
|
||||
getHomeDir() : QDir::currentPath());
|
||||
defaul["default_hash"] = hashBox::getDefault();
|
||||
defaul["ical_expiry"] = "1W";
|
||||
defaul["cert_expiry"] = "80%";
|
||||
@ -117,7 +118,7 @@ void settings::set(QString key, QString value)
|
||||
if (key == "workingdir") {
|
||||
if (!QDir(value).exists())
|
||||
return;
|
||||
value = QDir::toNativeSeparators(value);
|
||||
value = relativePath(value);
|
||||
}
|
||||
if (hostspecific.contains(key))
|
||||
key += QString(":%1").arg(hostId());
|
||||
|
||||
@ -463,11 +463,7 @@ int MainWindow::open_default_db()
|
||||
|
||||
void MainWindow::default_database()
|
||||
{
|
||||
if (portable_app())
|
||||
return;
|
||||
|
||||
QFile file(defaultdb());
|
||||
QFileInfo fi(currentDB);
|
||||
|
||||
if (currentDB.isEmpty()) {
|
||||
file.remove();
|
||||
@ -479,7 +475,7 @@ void MainWindow::default_database()
|
||||
if (OpenDb::isRemoteDB(currentDB))
|
||||
ba = filename2bytearray(currentDB);
|
||||
else
|
||||
ba = filename2bytearray(fi.canonicalFilePath());
|
||||
ba = filename2bytearray(relativePath(currentDB));
|
||||
ba += '\n';
|
||||
file.write(ba);
|
||||
/* write() failed? Harmless. Only inconvenient */
|
||||
@ -585,6 +581,9 @@ void MainWindow::update_history(QString fname)
|
||||
QFile file;
|
||||
int pos;
|
||||
|
||||
if (!OpenDb::isRemoteDB(fname))
|
||||
fname = relativePath(fname);
|
||||
|
||||
pos = history.indexOf(fname);
|
||||
if (pos == 0)
|
||||
return; /* no changes */
|
||||
@ -597,9 +596,6 @@ void MainWindow::update_history(QString fname)
|
||||
|
||||
update_history_menu();
|
||||
|
||||
if (portable_app())
|
||||
return;
|
||||
|
||||
file.setFileName(dbhistory());
|
||||
if (!file.open(QIODevice::ReadWrite))
|
||||
return;
|
||||
|
||||
@ -100,10 +100,8 @@ void MainWindow::init_menu()
|
||||
this, SLOT(openRemoteSqlDB()))
|
||||
->setEnabled(OpenDb::hasRemoteDrivers());
|
||||
file->addMenu(historyMenu);
|
||||
if (!portable_app()) {
|
||||
file->addAction(tr("Set as default DataBase"), this,
|
||||
file->addAction(tr("Set as default DataBase"), this,
|
||||
SLOT(default_database()));
|
||||
}
|
||||
acList += file->addAction(tr("Close DataBase"), this,
|
||||
SLOT(close_database()), QKeySequence::Close);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user