Skip to content

Commit 31508e1

Browse files
committed
Honor environment variable KRAFT_DATA_DIR
If this is set Kraft looks for Kraft2.ini in that to find the current dir. Should make synced environments easier to handle. Fixes #267
1 parent 2b14bcc commit 31508e1

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/addressproviderakonadi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool AddressProviderAkonadi::init()
5252
// See https://invent.kde.org/pim/akonadi/-/merge_requests/189
5353
qDebug() << "Akonadi broken: " << Akonadi::ServerManager::brokenReason();
5454
} else if (Akonadi::ServerManager::state() == Akonadi::ServerManager::Running) {
55-
qDebug() << "** Akonadi is already running";
55+
// qDebug() << "** Akonadi is already running";
5656
mSession = Session::defaultSession();
5757
_akonadiUp = true;
5858
} else if (Akonadi::Control::start()) {

src/defaultprovider.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,37 @@ bool writeSyncedSettingsCurrDir(const QString basePath, const QString& currKraft
7070
// link is pointing to a valid directory
7171
QString polishedBaseDir()
7272
{
73-
7473
QString re;
75-
const QString base = KraftSettings::self()->kraftV2BaseDir();
74+
QString base; // the base directory
75+
76+
auto checkBase = [](const QString& b) {
77+
QFileInfo fi(b);
78+
return (fi.exists() && fi.isDir() && fi.isWritable());
79+
};
80+
81+
// the environment variable KRAFT_DATA_DIR has precedence.
82+
const QString envBase = qgetenv("KRAFT_DATA_DIR");
83+
if (!envBase.isEmpty()) {
84+
if (checkBase(envBase)) {
85+
base = envBase;
86+
qDebug() << "Kraft data dir from Environment:" << base;
87+
}
88+
}
89+
7690
if (base.isEmpty()) {
77-
qDebug() << "No v2 base dir in config file";
91+
const auto settingsBase = KraftSettings::self()->kraftV2BaseDir();
92+
if (checkBase(settingsBase)) {
93+
base = settingsBase;
94+
}
95+
}
96+
97+
if (base.isEmpty()) {
98+
qDebug() << "No v2 base dir in config file or via KRAFT_DATA_DIR env var";
7899
return QString();
79100
}
80101

81102
QFileInfo fiLink(base, "current");
82-
83-
if (fiLink.isSymLink()) { // Migrate oder pre-Kraft 2.0 installations
103+
if (fiLink.isSymLink()) { // Migrate pre-Kraft 2.0 installations which used a current-link
84104
QFileInfo fiTarget(fiLink.symLinkTarget()); // full path
85105

86106
// write the settings file

src/myidentity.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void MyIdentity::load()
112112
} else {
113113
// check if the vcard can be read
114114

115-
_source = Source::Manual;
116115
const QString file = identityFile();
117116
qDebug() << "looking up my identity in vcard file"<< file;
118117
QFile f(file);
@@ -126,9 +125,11 @@ void MyIdentity::load()
126125
contact = list.at(0);
127126
contact.insertCustom(CUSTOM_ADDRESS_MARKER, "manual");
128127
}
128+
_source = Source::Manual;
129129
}
130130
} else {
131131
qDebug() << "VCard file does not exist!";
132+
_source = Source::Unknown;
132133
}
133134
slotAddresseeFound(myUid, contact);
134135
}

src/portal.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ void Portal::show()
136136
slotStartupChecks();
137137

138138
if ( mCmdLineArgs ) {
139-
slotStatusMsg( i18n( "Check commandline actions" ) );
140139
const QString uuid = mCmdLineArgs->value("d");
141140
if ( ! uuid.isEmpty() ) {
142141
slotPrintPDF(uuid);
@@ -500,14 +499,13 @@ void Portal::slotReceivedMyAddress( const QString& uid, const KContacts::Address
500499
const QString err = _myIdentity.errorMsg(uid);
501500
qDebug () << "My-Contact could not be found:" << err;
502501
}
503-
return;
504502
}
505503

506504
QString name = contact.formattedName();
507505
if( !name.isEmpty() ) {
508506
name = i18n("Welcome to Kraft, %1", name);
509-
statusBar()->showMessage(name, 30*1000);
510507
}
508+
slotStatusMsg(name);
511509
}
512510

513511
bool Portal::queryClose()

0 commit comments

Comments
 (0)