mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Extract class Journal from class Database
- const-ify Transaction and UndoAction - Clang-tidying
This commit is contained in:
parent
b15cddd562
commit
f72c4fda52
35 changed files with 416 additions and 321 deletions
|
@ -14,6 +14,7 @@ set (timew_SRCS CLI.cpp CLI.h
|
|||
Extensions.cpp Extensions.h
|
||||
Interval.cpp Interval.h
|
||||
IntervalFactory.cpp IntervalFactory.h
|
||||
Journal.cpp Journal.h
|
||||
Range.cpp Range.h
|
||||
Rules.cpp Rules.h
|
||||
TagInfo.cpp TagInfo.h
|
||||
|
|
123
src/Database.cpp
123
src/Database.cpp
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016, 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -26,17 +26,16 @@
|
|||
|
||||
#include <Database.h>
|
||||
#include <format.h>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
#include <TransactionsFactory.h>
|
||||
#include <JSON.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <timew.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Database::initialize (const std::string& location)
|
||||
void Database::initialize (const std::string& location, Journal& journal)
|
||||
{
|
||||
_location = location;
|
||||
_journal = &journal;
|
||||
initializeTagDatabase ();
|
||||
}
|
||||
|
||||
|
@ -122,7 +121,7 @@ void Database::addInterval (const Interval& interval, bool verbose)
|
|||
// created on demand.
|
||||
auto df = getDatafile (interval.start.year (), interval.start.month ());
|
||||
_files[df].addInterval (interval);
|
||||
recordIntervalAction ("", interval.json ());
|
||||
_journal->recordIntervalAction ("", interval.json ());
|
||||
}
|
||||
|
||||
void Database::deleteInterval (const Interval& interval)
|
||||
|
@ -139,8 +138,7 @@ void Database::deleteInterval (const Interval& interval)
|
|||
auto df = getDatafile (interval.start.year (), interval.start.month ());
|
||||
|
||||
_files[df].deleteInterval (interval);
|
||||
|
||||
recordIntervalAction (interval.json (), "");
|
||||
_journal->recordIntervalAction (interval.json (), "");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -161,115 +159,6 @@ void Database::modifyInterval (const Interval& from, const Interval& to, bool ve
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Database::startTransaction ()
|
||||
{
|
||||
if (_currentTransaction != nullptr)
|
||||
{
|
||||
throw "Subsequent call to start transaction";
|
||||
}
|
||||
|
||||
_currentTransaction = std::make_shared <Transaction> ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Database::endTransaction ()
|
||||
{
|
||||
if (_currentTransaction == nullptr)
|
||||
{
|
||||
throw "Call to end non-existent transaction";
|
||||
}
|
||||
|
||||
File undo (_location + "/undo.data");
|
||||
|
||||
if (undo.open ())
|
||||
{
|
||||
undo.append (_currentTransaction->toString());
|
||||
|
||||
undo.close ();
|
||||
_currentTransaction.reset ();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw format ("Unable to write the undo transaction to {1}", undo._data);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Record undoable actions. There are several types:
|
||||
// interval changes to stored intervals
|
||||
// config changes to configuration
|
||||
//
|
||||
// Actions are only recorded if a transaction is open
|
||||
//
|
||||
void Database::recordUndoAction (
|
||||
const std::string &type,
|
||||
const std::string &before,
|
||||
const std::string &after)
|
||||
{
|
||||
if (_currentTransaction == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_currentTransaction->addUndoAction (type, before, after);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Database::recordConfigAction (
|
||||
const std::string& before,
|
||||
const std::string& after)
|
||||
{
|
||||
recordUndoAction ("config", before, after);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Database::recordIntervalAction (
|
||||
const std::string& before,
|
||||
const std::string& after)
|
||||
{
|
||||
recordUndoAction ("interval", before, after);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Transaction Database::popLastTransaction ()
|
||||
{
|
||||
File undo (_location + "/undo.data");
|
||||
|
||||
std::vector <std::string> read_lines;
|
||||
undo.read (read_lines);
|
||||
undo.close ();
|
||||
|
||||
TransactionsFactory transactionsFactory;
|
||||
|
||||
for (auto& line: read_lines)
|
||||
{
|
||||
transactionsFactory.parseLine (line);
|
||||
}
|
||||
|
||||
std::vector <Transaction> transactions = transactionsFactory.get ();
|
||||
|
||||
if (transactions.empty ())
|
||||
{
|
||||
return Transaction {};
|
||||
}
|
||||
|
||||
Transaction last = transactions.back ();
|
||||
transactions.pop_back ();
|
||||
|
||||
File::remove (undo._data);
|
||||
undo.open ();
|
||||
|
||||
for (auto& transaction : transactions)
|
||||
{
|
||||
undo.append (transaction.toString ());
|
||||
}
|
||||
|
||||
undo.close ();
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Database::dump () const
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2016, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016, 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -34,12 +34,13 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <TagInfoDatabase.h>
|
||||
#include <Journal.h>
|
||||
|
||||
class Database
|
||||
{
|
||||
public:
|
||||
Database () = default;
|
||||
void initialize (const std::string&);
|
||||
void initialize (const std::string&, Journal& journal);
|
||||
void commit ();
|
||||
std::vector <std::string> files () const;
|
||||
|
||||
|
@ -50,13 +51,6 @@ public:
|
|||
void deleteInterval (const Interval&);
|
||||
void modifyInterval (const Interval&, const Interval &, bool verbose);
|
||||
|
||||
void startTransaction ();
|
||||
void endTransaction ();
|
||||
void recordConfigAction(const std::string&, const std::string&);
|
||||
void recordIntervalAction(const std::string&, const std::string&);
|
||||
|
||||
Transaction popLastTransaction ();
|
||||
|
||||
std::string dump () const;
|
||||
|
||||
private:
|
||||
|
@ -65,13 +59,11 @@ private:
|
|||
void initializeDatafiles ();
|
||||
void initializeTagDatabase ();
|
||||
|
||||
void recordUndoAction (const std::string &, const std::string &, const std::string &);
|
||||
|
||||
private:
|
||||
std::string _location {"~/.timewarrior/data"};
|
||||
std::vector <Datafile> _files {};
|
||||
TagInfoDatabase _tagInfoDatabase {};
|
||||
std::shared_ptr <Transaction> _currentTransaction = nullptr;
|
||||
Journal* _journal {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
139
src/Journal.cpp
Normal file
139
src/Journal.cpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// https://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <FS.h>
|
||||
#include <format.h>
|
||||
#include <Journal.h>
|
||||
#include <TransactionsFactory.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Journal::initialize (const std::string& location)
|
||||
{
|
||||
_location = location;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Journal::startTransaction ()
|
||||
{
|
||||
if (_currentTransaction != nullptr)
|
||||
{
|
||||
throw "Subsequent call to start transaction";
|
||||
}
|
||||
|
||||
_currentTransaction = std::make_shared <Transaction> ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Journal::endTransaction ()
|
||||
{
|
||||
if (_currentTransaction == nullptr)
|
||||
{
|
||||
throw "Call to end non-existent transaction";
|
||||
}
|
||||
|
||||
File undo (_location);
|
||||
|
||||
if (undo.open ())
|
||||
{
|
||||
undo.append (_currentTransaction->toString());
|
||||
|
||||
undo.close ();
|
||||
_currentTransaction.reset ();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw format ("Unable to write the undo transaction to {1}", undo._data);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Journal::recordConfigAction (const std::string& before, const std::string& after)
|
||||
{
|
||||
recordUndoAction ("config", before, after);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Journal::recordIntervalAction (const std::string& before, const std::string& after)
|
||||
{
|
||||
recordUndoAction ("interval", before, after);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Record undoable actions. There are several types:
|
||||
// interval changes to stored intervals
|
||||
// config changes to configuration
|
||||
//
|
||||
// Actions are only recorded if a transaction is open
|
||||
//
|
||||
void Journal::recordUndoAction (
|
||||
const std::string &type,
|
||||
const std::string &before,
|
||||
const std::string &after)
|
||||
{
|
||||
if (_currentTransaction != nullptr)
|
||||
{
|
||||
_currentTransaction->addUndoAction (type, before, after);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Transaction Journal::popLastTransaction ()
|
||||
{
|
||||
File undo (_location);
|
||||
|
||||
std::vector <std::string> read_lines;
|
||||
undo.read (read_lines);
|
||||
undo.close ();
|
||||
|
||||
TransactionsFactory transactionsFactory;
|
||||
|
||||
for (auto& line: read_lines)
|
||||
{
|
||||
transactionsFactory.parseLine (line);
|
||||
}
|
||||
|
||||
std::vector <Transaction> transactions = transactionsFactory.get ();
|
||||
|
||||
if (transactions.empty ())
|
||||
{
|
||||
return Transaction {};
|
||||
}
|
||||
|
||||
Transaction last = transactions.back ();
|
||||
transactions.pop_back ();
|
||||
|
||||
File::remove (undo._data);
|
||||
undo.open ();
|
||||
|
||||
for (auto& transaction : transactions)
|
||||
{
|
||||
undo.append (transaction.toString ());
|
||||
}
|
||||
|
||||
undo.close ();
|
||||
|
||||
return last;
|
||||
}
|
57
src/Journal.h
Normal file
57
src/Journal.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// https://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_JOURNAL
|
||||
#define INCLUDED_JOURNAL
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <Transaction.h>
|
||||
|
||||
class Journal
|
||||
{
|
||||
public:
|
||||
Journal() = default;
|
||||
|
||||
void initialize(const std::string&);
|
||||
|
||||
void startTransaction ();
|
||||
void endTransaction ();
|
||||
void recordConfigAction(const std::string&, const std::string&);
|
||||
void recordIntervalAction(const std::string&, const std::string&);
|
||||
|
||||
Transaction popLastTransaction();
|
||||
|
||||
private:
|
||||
void recordUndoAction (const std::string &, const std::string &, const std::string &);
|
||||
|
||||
std::string _location {"~/.timewarrior/data/undo.data"};
|
||||
std::shared_ptr <Transaction> _currentTransaction = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -500,7 +500,7 @@ std::string Rules::parseGroup (const std::vector <std::string>& tokens)
|
|||
// only sees the top-level settings. This has the desirable effect of adding as
|
||||
// an override any setting which resides in an imported file.
|
||||
bool Rules::setConfigVariable (
|
||||
Database& database,
|
||||
Journal& journal,
|
||||
const Rules& rules,
|
||||
std::string name,
|
||||
std::string value,
|
||||
|
@ -540,7 +540,7 @@ bool Rules::setConfigVariable (
|
|||
auto before = line;
|
||||
line = line.substr (0, pos) + name + " = " + value;
|
||||
|
||||
database.recordConfigAction (before, line);
|
||||
journal.recordConfigAction (before, line);
|
||||
|
||||
change = true;
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ bool Rules::setConfigVariable (
|
|||
auto before = line;
|
||||
line = line.substr (0, pos) + leaf + " " + value;
|
||||
|
||||
database.recordConfigAction (before, line);
|
||||
journal.recordConfigAction (before, line);
|
||||
|
||||
change = true;
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ bool Rules::setConfigVariable (
|
|||
// Add new line.
|
||||
lines.push_back (name + " = " + json::encode (value));
|
||||
|
||||
database.recordConfigAction ("", lines.back ());
|
||||
journal.recordConfigAction ("", lines.back ());
|
||||
|
||||
change = true;
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ bool Rules::setConfigVariable (
|
|||
// Add new line.
|
||||
lines.push_back (name + " = " + json::encode (value));
|
||||
|
||||
database.recordConfigAction ("", lines.back ());
|
||||
journal.recordConfigAction ("", lines.back ());
|
||||
|
||||
change = true;
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ bool Rules::setConfigVariable (
|
|||
// 1 - found and not removed
|
||||
// 2 - not found
|
||||
int Rules::unsetConfigVariable (
|
||||
Database& database,
|
||||
Journal& journal,
|
||||
const Rules& rules,
|
||||
std::string name,
|
||||
bool confirmation /* = false */)
|
||||
|
@ -667,7 +667,7 @@ int Rules::unsetConfigVariable (
|
|||
if (! confirmation ||
|
||||
confirm (format ("Are you sure you want to remove '{1}'?", name)))
|
||||
{
|
||||
database.recordConfigAction (line, "");
|
||||
journal.recordConfigAction (line, "");
|
||||
|
||||
line = "";
|
||||
change = true;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2015 - 2016, 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -32,6 +32,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <Database.h>
|
||||
#include <Journal.h>
|
||||
|
||||
class Rules
|
||||
{
|
||||
|
@ -55,12 +56,12 @@ public:
|
|||
|
||||
std::string dump () const;
|
||||
|
||||
static bool setConfigVariable (Database& database,
|
||||
static bool setConfigVariable (Journal& journal,
|
||||
const Rules& rules,
|
||||
std::string name,
|
||||
std::string value,
|
||||
bool confirmation /* = false */);
|
||||
static int unsetConfigVariable (Database& database,
|
||||
static int unsetConfigVariable (Journal& journal,
|
||||
const Rules& rules,
|
||||
std::string name,
|
||||
bool confirmation /* = false */);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string>
|
||||
#include <Transaction.h>
|
||||
|
||||
void Transaction::addUndoAction (
|
||||
|
@ -35,12 +34,12 @@ void Transaction::addUndoAction (
|
|||
_actions.emplace_back (type, before, after);
|
||||
}
|
||||
|
||||
std::vector<UndoAction> Transaction::getActions ()
|
||||
std::vector<UndoAction> Transaction::getActions () const
|
||||
{
|
||||
return _actions;
|
||||
}
|
||||
|
||||
std::string Transaction::toString ()
|
||||
std::string Transaction::toString () const
|
||||
{
|
||||
std::string output = "txn:\n";
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ class Transaction
|
|||
public:
|
||||
void addUndoAction(const std::string&, const std::string&, const std::string&);
|
||||
|
||||
std::string toString();
|
||||
std::string toString() const;
|
||||
|
||||
std::vector<UndoAction> getActions ();
|
||||
std::vector<UndoAction> getActions () const;
|
||||
|
||||
private:
|
||||
std::vector<UndoAction> _actions {};
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <vector>
|
||||
#include "TransactionsFactory.h"
|
||||
#include "Transaction.h"
|
||||
#include <TransactionsFactory.h>
|
||||
|
||||
void TransactionsFactory::parseLine (const std::string& line)
|
||||
{
|
||||
|
|
|
@ -25,35 +25,30 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <UndoAction.h>
|
||||
#include <utility>
|
||||
|
||||
UndoAction::UndoAction (
|
||||
const std::string& type,
|
||||
const std::string& before,
|
||||
const std::string& after)
|
||||
{
|
||||
_type = type;
|
||||
_before = before;
|
||||
_after = after;
|
||||
}
|
||||
UndoAction::UndoAction (std::string type, std::string before, std::string after) :
|
||||
_type (std::move (type)), _before (std::move (before)), _after (std::move (after))
|
||||
{}
|
||||
|
||||
std::string UndoAction::toString ()
|
||||
std::string UndoAction::toString () const
|
||||
{
|
||||
return " type: " + _type + "\n" +
|
||||
" before: " + _before + "\n" +
|
||||
" after: " + _after + "\n";
|
||||
}
|
||||
|
||||
std::string UndoAction::getType ()
|
||||
std::string UndoAction::getType () const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
std::string UndoAction::getBefore ()
|
||||
std::string UndoAction::getBefore () const
|
||||
{
|
||||
return _before;
|
||||
}
|
||||
|
||||
std::string UndoAction::getAfter ()
|
||||
std::string UndoAction::getAfter () const
|
||||
{
|
||||
return _after;
|
||||
}
|
||||
|
|
|
@ -32,18 +32,18 @@
|
|||
class UndoAction
|
||||
{
|
||||
public:
|
||||
UndoAction(const std::string&, const std::string&, const std::string&);
|
||||
UndoAction(std::string, std::string, std::string);
|
||||
|
||||
std::string getType();
|
||||
std::string getBefore();
|
||||
std::string getAfter();
|
||||
std::string getType() const;
|
||||
std::string getBefore() const;
|
||||
std::string getAfter() const;
|
||||
|
||||
std::string toString ();
|
||||
std::string toString () const;
|
||||
|
||||
private:
|
||||
std::string _type;
|
||||
std::string _before;
|
||||
std::string _after;
|
||||
const std::string _type;
|
||||
const std::string _before;
|
||||
const std::string _after;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
int CmdAnnotate (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
std::set <int> ids = cli.getIds ();
|
||||
std::string annotation = cli.getAnnotation ();
|
||||
|
@ -52,7 +53,7 @@ int CmdAnnotate (
|
|||
|
||||
bool dirty = true;
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
for (auto& id : ids)
|
||||
{
|
||||
|
@ -111,7 +112,7 @@ int CmdAnnotate (
|
|||
}
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -31,7 +31,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdCancel (
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// If there is an open interval, cancel it by deleting it..
|
||||
auto latest = getLatestInterval (database);
|
||||
|
@ -44,9 +45,9 @@ int CmdCancel (
|
|||
return 0;
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
database.deleteInterval(latest);
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << "Canceled active time tracking.\n";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -40,7 +40,7 @@
|
|||
int CmdConfig (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Journal& journal)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
|
@ -67,7 +67,7 @@ int CmdConfig (
|
|||
|
||||
bool change = false;
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// timew config name value
|
||||
// timew config name ""
|
||||
|
@ -84,7 +84,7 @@ int CmdConfig (
|
|||
value += words[i];
|
||||
}
|
||||
|
||||
change = Rules::setConfigVariable (database, rules, name, value, confirmation);
|
||||
change = Rules::setConfigVariable (journal, rules, name, value, confirmation);
|
||||
|
||||
if (!change)
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ int CmdConfig (
|
|||
else
|
||||
{
|
||||
bool found = false;
|
||||
rc = Rules::unsetConfigVariable (database, rules, name, confirmation);
|
||||
rc = Rules::unsetConfigVariable (journal, rules, name, confirmation);
|
||||
if (rc == 0)
|
||||
{
|
||||
change = true;
|
||||
|
@ -112,7 +112,7 @@ int CmdConfig (
|
|||
}
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -33,7 +33,8 @@
|
|||
int CmdContinue (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds();
|
||||
|
@ -73,7 +74,7 @@ int CmdContinue (
|
|||
Datetime start_time;
|
||||
Datetime end_time;
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
if (filter.start.toEpoch () != 0)
|
||||
{
|
||||
|
@ -112,7 +113,7 @@ int CmdContinue (
|
|||
validate (cli, rules, database, to_copy);
|
||||
database.addInterval (to_copy, rules.getBoolean ("verbose"));
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << intervalSummarize (database, rules, to_copy);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -27,12 +27,14 @@
|
|||
#include <timew.h>
|
||||
#include <format.h>
|
||||
#include <iostream>
|
||||
#include <src/Journal.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdDelete (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather IDs.
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -45,7 +47,7 @@ int CmdDelete (
|
|||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
bool dirty = true;
|
||||
|
||||
|
@ -79,7 +81,7 @@ int CmdDelete (
|
|||
std::cout << "Deleted @" << id << '\n';
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -34,7 +34,8 @@
|
|||
int CmdFill (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
|
@ -46,7 +47,7 @@ int CmdFill (
|
|||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Apply tags to ids.
|
||||
for (auto& id : ids)
|
||||
|
@ -67,7 +68,7 @@ int CmdFill (
|
|||
// Note: Feedback generated inside autoFill().
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -36,7 +36,8 @@
|
|||
int CmdJoin (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -62,7 +63,7 @@ int CmdJoin (
|
|||
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
auto first_id = *ids.begin ();
|
||||
auto second_id = *ids.rbegin ();
|
||||
|
@ -86,7 +87,7 @@ int CmdJoin (
|
|||
validate (cli, rules, database, combined);
|
||||
database.addInterval (combined, rules.getBoolean ("verbose"));
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -36,7 +36,8 @@
|
|||
int CmdLengthen (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -53,7 +54,7 @@ int CmdLengthen (
|
|||
delta = arg.attribute ("raw");
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
|
@ -104,7 +105,7 @@ int CmdLengthen (
|
|||
std::cout << "Lengthened @" << id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
int CmdModify (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
auto filter = getFilter (cli);
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -84,13 +85,13 @@ int CmdModify (
|
|||
if (!interval.is_open () && (interval.start > interval.end))
|
||||
throw format ("Cannot modify interval @{1} where start is after end.", id);
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
database.deleteInterval (tracked[tracked.size() - id]);
|
||||
validate(cli, rules, database, interval);
|
||||
database.addInterval(interval, verbose);
|
||||
|
||||
database.endTransaction();
|
||||
journal.endTransaction();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -36,7 +36,8 @@
|
|||
int CmdMove (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather ID and TAGs.
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -51,7 +52,7 @@ int CmdMove (
|
|||
throw std::string ("ID must be specified. See 'timew help move'.");
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
int id = *ids.begin ();
|
||||
|
||||
|
@ -109,7 +110,7 @@ int CmdMove (
|
|||
validate (cli, rules, database, i);
|
||||
database.addInterval (i, rules.getBoolean ("verbose"));
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << "Moved @" << id << " to " << i.start.toISOLocalExtended () << '\n';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2017 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -36,7 +36,8 @@
|
|||
int CmdResize (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
|
@ -51,7 +52,7 @@ int CmdResize (
|
|||
delta = arg.attribute ("raw");
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
|
@ -79,7 +80,7 @@ int CmdResize (
|
|||
std::cout << "Resized @" << id << " to " << dur.formatHours () << '\n';
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -36,7 +36,8 @@
|
|||
int CmdShorten (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
|
@ -51,7 +52,7 @@ int CmdShorten (
|
|||
delta = arg.attribute ("raw");
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
|
@ -105,7 +106,7 @@ int CmdShorten (
|
|||
std::cout << "Shortened @" << id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -36,7 +36,8 @@
|
|||
int CmdSplit (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
|
@ -48,7 +49,7 @@ int CmdSplit (
|
|||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Apply tags to ids.
|
||||
for (auto& id : ids)
|
||||
|
@ -86,7 +87,7 @@ int CmdSplit (
|
|||
std::cout << "Split @" << id << '\n';
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
int CmdStart (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Add a new open interval, which may have a defined start time.
|
||||
auto filter = getFilter (cli);
|
||||
|
@ -44,7 +45,7 @@ int CmdStart (
|
|||
|
||||
auto latest = getLatestInterval (database);
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// If the latest interval is open, close it.
|
||||
if (latest.is_open ())
|
||||
|
@ -96,7 +97,7 @@ int CmdStart (
|
|||
if (rules.getBoolean ("verbose"))
|
||||
std::cout << intervalSummarize (database, rules, started);
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -44,7 +44,8 @@ template <class T> T setIntersect (
|
|||
int CmdStop (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Load the most recent interval.
|
||||
auto filter = getFilter (cli);
|
||||
|
@ -54,7 +55,7 @@ int CmdStop (
|
|||
if (! latest.is_open ())
|
||||
throw std::string ("There is no active time tracking.");
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
Interval modified {latest};
|
||||
|
||||
|
@ -108,7 +109,7 @@ int CmdStop (
|
|||
std::cout << '\n' << intervalSummarize (database, rules, modified);
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -35,7 +35,8 @@
|
|||
int CmdTag (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -53,7 +54,7 @@ int CmdTag (
|
|||
|
||||
bool dirty = true;
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
for (auto& id : ids)
|
||||
{
|
||||
|
@ -111,7 +112,7 @@ int CmdTag (
|
|||
}
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -32,7 +32,8 @@
|
|||
int CmdTrack (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
auto filter = getFilter (cli);
|
||||
|
||||
|
@ -40,9 +41,9 @@ int CmdTrack (
|
|||
// the 'track' command behave like 'start', so delegate to CmdStart.
|
||||
if (! filter.is_started () ||
|
||||
! filter.is_ended ())
|
||||
return CmdStart (cli, rules, database);
|
||||
return CmdStart (cli, rules, database, journal);
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Validation must occur before flattening.
|
||||
validate (cli, rules, database, filter);
|
||||
|
@ -55,7 +56,7 @@ int CmdTrack (
|
|||
std::cout << intervalSummarize (database, rules, interval);
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ static void undoIntervalAction(UndoAction& action, Database& database)
|
|||
database.modifyInterval (after, before, false);
|
||||
}
|
||||
|
||||
static void undoConfigAction (UndoAction& action, Rules &rules, Database& database)
|
||||
static void undoConfigAction (UndoAction& action, Rules &rules, Journal& journal)
|
||||
{
|
||||
const std::string& before = action.getBefore ();
|
||||
|
||||
|
@ -47,7 +47,7 @@ static void undoConfigAction (UndoAction& action, Rules &rules, Database& databa
|
|||
auto pos = after.find (' ');
|
||||
std::string name = after.substr (0, pos);
|
||||
|
||||
Rules::unsetConfigVariable (database, rules, name, false);
|
||||
Rules::unsetConfigVariable (journal, rules, name, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -55,14 +55,14 @@ static void undoConfigAction (UndoAction& action, Rules &rules, Database& databa
|
|||
std::string name = before.substr (0, pos-1);
|
||||
std::string value = before.substr (pos+1, before.length ());
|
||||
|
||||
Rules::setConfigVariable (database, rules, name, value, false);
|
||||
Rules::setConfigVariable (journal, rules, name, value, false);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdUndo (Rules& rules, Database& database)
|
||||
int CmdUndo (Rules& rules, Database& database, Journal& journal)
|
||||
{
|
||||
Transaction transaction = database.popLastTransaction ();
|
||||
Transaction transaction = journal.popLastTransaction ();
|
||||
|
||||
std::vector <UndoAction> actions = transaction.getActions ();
|
||||
|
||||
|
@ -88,7 +88,7 @@ int CmdUndo (Rules& rules, Database& database)
|
|||
}
|
||||
else if (type == "config")
|
||||
{
|
||||
undoConfigAction (action, rules, database);
|
||||
undoConfigAction (action, rules, journal);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -35,7 +35,8 @@
|
|||
int CmdUntag (
|
||||
const CLI& cli,
|
||||
Rules& rules,
|
||||
Database& database)
|
||||
Database& database,
|
||||
Journal& journal)
|
||||
{
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds ();
|
||||
|
@ -46,7 +47,7 @@ int CmdUntag (
|
|||
throw std::string ("At least one tag must be specified. See 'timew help untag'.");
|
||||
}
|
||||
|
||||
database.startTransaction ();
|
||||
journal.startTransaction ();
|
||||
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
|
@ -111,7 +112,7 @@ int CmdUntag (
|
|||
}
|
||||
}
|
||||
|
||||
database.endTransaction ();
|
||||
journal.endTransaction ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,37 +31,38 @@
|
|||
#include <Rules.h>
|
||||
#include <Database.h>
|
||||
#include <Extensions.h>
|
||||
#include <Journal.h>
|
||||
|
||||
int CmdAnnotate (const CLI&, Rules&, Database& );
|
||||
int CmdCancel ( Rules&, Database& );
|
||||
int CmdConfig (const CLI&, Rules&, Database& );
|
||||
int CmdContinue (const CLI&, Rules&, Database& );
|
||||
int CmdAnnotate (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdCancel ( Rules&, Database&, Journal& );
|
||||
int CmdConfig (const CLI&, Rules&, Journal& );
|
||||
int CmdContinue (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdDefault ( Rules&, Database& );
|
||||
int CmdDelete (const CLI&, Rules&, Database& );
|
||||
int CmdDelete (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdDiagnostics ( Rules&, Database&, const Extensions&);
|
||||
int CmdExport (const CLI&, Rules&, Database& );
|
||||
int CmdExtensions ( Rules&, const Extensions&);
|
||||
int CmdFill (const CLI&, Rules&, Database& );
|
||||
int CmdFill (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdGaps (const CLI&, Rules&, Database& );
|
||||
int CmdGet (const CLI&, Rules&, Database& );
|
||||
int CmdHelpUsage ( const Extensions&);
|
||||
int CmdHelp (const CLI&, const Extensions&);
|
||||
int CmdJoin (const CLI&, Rules&, Database& );
|
||||
int CmdLengthen (const CLI&, Rules&, Database& );
|
||||
int CmdModify (const CLI&, Rules&, Database& );
|
||||
int CmdMove (const CLI&, Rules&, Database& );
|
||||
int CmdJoin (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdLengthen (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdModify (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdMove (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdReport (const CLI&, Rules&, Database&, const Extensions&);
|
||||
int CmdResize (const CLI&, Rules&, Database& );
|
||||
int CmdShorten (const CLI&, Rules&, Database& );
|
||||
int CmdResize (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdShorten (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdShow ( Rules& );
|
||||
int CmdSplit (const CLI&, Rules&, Database& );
|
||||
int CmdStart (const CLI&, Rules&, Database& );
|
||||
int CmdStop (const CLI&, Rules&, Database& );
|
||||
int CmdTag (const CLI&, Rules&, Database& );
|
||||
int CmdSplit (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdStart (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdStop (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdTag (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdTags (const CLI&, Rules&, Database& );
|
||||
int CmdTrack (const CLI&, Rules&, Database& );
|
||||
int CmdUndo ( Rules&, Database& );
|
||||
int CmdUntag (const CLI&, Rules&, Database& );
|
||||
int CmdTrack (const CLI&, Rules&, Database&, Journal& );
|
||||
int CmdUndo ( Rules&, Database&, Journal& );
|
||||
int CmdUntag (const CLI&, Rules&, Database&, Journal& );
|
||||
|
||||
int CmdChartDay (const CLI&, Rules&, Database& );
|
||||
int CmdChartWeek (const CLI&, Rules&, Database& );
|
||||
|
|
47
src/init.cpp
47
src/init.cpp
|
@ -118,9 +118,10 @@ void initializeEntities (CLI& cli)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void initializeDataAndRules (
|
||||
void initializeDataJournalAndRules (
|
||||
const CLI& cli,
|
||||
Database& database,
|
||||
Journal& journal,
|
||||
Rules& rules)
|
||||
{
|
||||
// Rose tint my world, make me safe from my trouble and pain.
|
||||
|
@ -215,8 +216,9 @@ void initializeDataAndRules (
|
|||
}
|
||||
}
|
||||
|
||||
journal.initialize (data._data + "/undo.data");
|
||||
// Initialize the database (no data read), but files are enumerated.
|
||||
database.initialize (data._data);
|
||||
database.initialize (data._data, journal);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -243,6 +245,7 @@ void initializeExtensions (
|
|||
int dispatchCommand (
|
||||
const CLI& cli,
|
||||
Database& database,
|
||||
Journal& journal,
|
||||
Rules& rules,
|
||||
const Extensions& extensions)
|
||||
{
|
||||
|
@ -259,41 +262,41 @@ int dispatchCommand (
|
|||
{
|
||||
// These signatures are expected to be all different, therefore no
|
||||
// command to fn mapping.
|
||||
if (command == "annotate") status = CmdAnnotate (cli, rules, database );
|
||||
else if (command == "cancel") status = CmdCancel ( rules, database );
|
||||
else if (command == "config") status = CmdConfig (cli, rules, database );
|
||||
else if (command == "continue") status = CmdContinue (cli, rules, database );
|
||||
if (command == "annotate") status = CmdAnnotate (cli, rules, database, journal );
|
||||
else if (command == "cancel") status = CmdCancel ( rules, database, journal );
|
||||
else if (command == "config") status = CmdConfig (cli, rules, journal );
|
||||
else if (command == "continue") status = CmdContinue (cli, rules, database, journal );
|
||||
else if (command == "day") status = CmdChartDay (cli, rules, database );
|
||||
else if (command == "delete") status = CmdDelete (cli, rules, database );
|
||||
else if (command == "delete") status = CmdDelete (cli, rules, database, journal );
|
||||
else if (command == "diagnostics") status = CmdDiagnostics ( rules, database, extensions);
|
||||
else if (command == "export") status = CmdExport (cli, rules, database );
|
||||
else if (command == "extensions") status = CmdExtensions ( rules, extensions);
|
||||
/*
|
||||
else if (command == "fill") status = CmdFill (cli, rules, database );
|
||||
*/
|
||||
else if (command == "fill") status = CmdFill (cli, rules, database, journal );
|
||||
//*/
|
||||
else if (command == "gaps") status = CmdGaps (cli, rules, database );
|
||||
else if (command == "get") status = CmdGet (cli, rules, database );
|
||||
else if (command == "help" ||
|
||||
command == "--help" ||
|
||||
command == "-h") status = CmdHelp (cli, extensions);
|
||||
else if (command == "join") status = CmdJoin (cli, rules, database );
|
||||
else if (command == "lengthen") status = CmdLengthen (cli, rules, database );
|
||||
else if (command == "modify") status = CmdModify (cli, rules, database );
|
||||
else if (command == "join") status = CmdJoin (cli, rules, database, journal );
|
||||
else if (command == "lengthen") status = CmdLengthen (cli, rules, database, journal );
|
||||
else if (command == "modify") status = CmdModify (cli, rules, database, journal );
|
||||
else if (command == "month") status = CmdChartMonth (cli, rules, database );
|
||||
else if (command == "move") status = CmdMove (cli, rules, database );
|
||||
else if (command == "move") status = CmdMove (cli, rules, database, journal );
|
||||
else if (command == "report") status = CmdReport (cli, rules, database, extensions);
|
||||
else if (command == "resize") status = CmdResize (cli, rules, database );
|
||||
else if (command == "shorten") status = CmdShorten (cli, rules, database );
|
||||
else if (command == "resize") status = CmdResize (cli, rules, database, journal );
|
||||
else if (command == "shorten") status = CmdShorten (cli, rules, database, journal );
|
||||
else if (command == "show") status = CmdShow ( rules );
|
||||
else if (command == "split") status = CmdSplit (cli, rules, database );
|
||||
else if (command == "start") status = CmdStart (cli, rules, database );
|
||||
else if (command == "stop") status = CmdStop (cli, rules, database );
|
||||
else if (command == "split") status = CmdSplit (cli, rules, database, journal );
|
||||
else if (command == "start") status = CmdStart (cli, rules, database, journal );
|
||||
else if (command == "stop") status = CmdStop (cli, rules, database, journal );
|
||||
else if (command == "summary") status = CmdSummary (cli, rules, database );
|
||||
else if (command == "tag") status = CmdTag (cli, rules, database );
|
||||
else if (command == "tag") status = CmdTag (cli, rules, database, journal );
|
||||
else if (command == "tags") status = CmdTags (cli, rules, database );
|
||||
else if (command == "track") status = CmdTrack (cli, rules, database );
|
||||
else if (command == "undo") status = CmdUndo ( rules, database );
|
||||
else if (command == "untag") status = CmdUntag (cli, rules, database );
|
||||
else if (command == "track") status = CmdTrack (cli, rules, database, journal );
|
||||
else if (command == "undo") status = CmdUndo ( rules, database, journal );
|
||||
else if (command == "untag") status = CmdUntag (cli, rules, database, journal );
|
||||
else if (command == "week") status = CmdChartWeek (cli, rules, database );
|
||||
else status = CmdReport (cli, rules, database, extensions);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2015 - 2018, Paul Beckingham, Federico Hernandez.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -79,10 +79,11 @@ int main (int argc, const char** argv)
|
|||
// Scan command line.
|
||||
cli.analyze ();
|
||||
|
||||
Journal journal;
|
||||
// Prepare the database, but do not read data.
|
||||
Database database;
|
||||
Rules rules;
|
||||
initializeDataAndRules (cli, database, rules);
|
||||
initializeDataJournalAndRules (cli, database, journal, rules);
|
||||
|
||||
// Load extension script info.
|
||||
// Re-analyze command because of the new extension entities.
|
||||
|
@ -91,7 +92,7 @@ int main (int argc, const char** argv)
|
|||
cli.analyze ();
|
||||
|
||||
// Dispatch to commands.
|
||||
status = dispatchCommand (cli, database, rules, extensions);
|
||||
status = dispatchCommand (cli, database, journal, rules, extensions);
|
||||
|
||||
// Save any outstanding changes.
|
||||
database.commit ();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2016 - 2019, Paul Beckingham, Federico Hernandez.
|
||||
// Copyright 2016 - 2019, Paul Beckingham, Federico Hernandez, Thomas Lauf.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -63,9 +63,9 @@ void validate (const CLI& cli, const Rules& rules, Database&, Interval&);
|
|||
// init.cpp
|
||||
bool lightweightVersionCheck (int, const char**);
|
||||
void initializeEntities (CLI&);
|
||||
void initializeDataAndRules (const CLI&, Database&, Rules&);
|
||||
void initializeDataJournalAndRules (const CLI&, Database&, Journal&, Rules&);
|
||||
void initializeExtensions (CLI&, const Rules&, Extensions&);
|
||||
int dispatchCommand (const CLI&, Database&, Rules&, const Extensions&);
|
||||
int dispatchCommand (const CLI&, Database&, Journal&, Rules&, const Extensions&);
|
||||
|
||||
// helper.cpp
|
||||
Color intervalColor (const std::set <std::string>&, const std::map <std::string, Color>&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue