mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Location object
- Implemented Location object to link a path with the data files found in that path. - Integrated into TDB.
This commit is contained in:
parent
7ff41a222a
commit
4cbc67b30b
5 changed files with 176 additions and 70 deletions
70
src/sandbox/Location.cpp
Normal file
70
src/sandbox/Location.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Location.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Location::Location ()
|
||||
: path ("")
|
||||
, pending (NULL)
|
||||
, completed (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Location::Location (const std::string& p)
|
||||
: path (p)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Location::Location (const Location& other)
|
||||
{
|
||||
path = other.path;
|
||||
pending = other.pending;
|
||||
completed = other.completed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Location& Location::operator= (const Location& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
path = other.path;
|
||||
pending = other.pending;
|
||||
completed = other.completed;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Location::~Location ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
49
src/sandbox/Location.h
Normal file
49
src/sandbox/Location.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INCLUDED_LOCATION
|
||||
#define INCLUDED_LOCATION
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
class Location
|
||||
{
|
||||
public:
|
||||
Location (); // Default constructor
|
||||
Location (const std::string&); // Default constructor
|
||||
Location (const Location&); // Copy constructor
|
||||
Location& operator= (const Location&); // Assignment operator
|
||||
~Location (); // Destructor
|
||||
|
||||
public:
|
||||
std::string path;
|
||||
FILE* pending;
|
||||
FILE* completed;
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,10 +1,10 @@
|
|||
PROJECT = 1.8
|
||||
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fstack-check
|
||||
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fno-stack-check
|
||||
LFLAGS =
|
||||
LIBS =
|
||||
OBJECTS = main.o Context.o TDB.o T.o ../Sequence.o ../Filter.o ../Att.o \
|
||||
Keymap.o ../Record.o ../Mod.o ../StringTable.o ../util.o ../text.o \
|
||||
../Date.o ../Config.o
|
||||
../Date.o ../Config.o Location.o
|
||||
|
||||
all: $(PROJECT)
|
||||
|
||||
|
|
|
@ -73,30 +73,32 @@ TDB::TDB ()
|
|||
TDB::TDB (const TDB& other)
|
||||
{
|
||||
throw std::string ("unimplemented TDB::TDB");
|
||||
mLocations = other.mLocations;
|
||||
mLock = other.mLock;
|
||||
mAllOpenAndLocked = false; // Deliberately so.
|
||||
|
||||
// Set all to NULL.
|
||||
foreach (location, mLocations)
|
||||
mLocations[location->first] = NULL;
|
||||
// mLocations = other.mLocations;
|
||||
// mFiles = other.mFiles;
|
||||
// mLock = other.mLock;
|
||||
// mAllOpenAndLocked = false; // Deliberately so.
|
||||
//
|
||||
// // Set all to NULL, otherwise we are duplicating open file handles.
|
||||
// foreach (file, mFiles)
|
||||
// mFiles[file->first] = NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
TDB& TDB::operator= (const TDB& other)
|
||||
{
|
||||
throw std::string ("unimplemented TDB::operator=");
|
||||
if (this != &other)
|
||||
{
|
||||
mLocations = other.mLocations;
|
||||
mLock = other.mLock;
|
||||
mAllOpenAndLocked = false; // Deliberately so.
|
||||
|
||||
// Set all to NULL.
|
||||
foreach (location, mLocations)
|
||||
mLocations[location->first] = NULL;
|
||||
}
|
||||
|
||||
// if (this != &other)
|
||||
// {
|
||||
// mLocations = other.mLocations;
|
||||
// mFiles = other.mFiles;
|
||||
// mLock = other.mLock;
|
||||
// mAllOpenAndLocked = false; // Deliberately so.
|
||||
//
|
||||
// // Set all to NULL, otherwise we are duplicating open file handles.
|
||||
// foreach (file, mFiles)
|
||||
// mFiles[file->first] = NULL;
|
||||
// }
|
||||
//
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -115,7 +117,7 @@ void TDB::location (const std::string& path)
|
|||
path +
|
||||
"' does not exist, or is not readable and writable.";
|
||||
|
||||
mLocations[path] = NULL;
|
||||
mLocations.push_back (Location (path));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -124,7 +126,10 @@ void TDB::lock (bool lockFile /* = true */)
|
|||
mLock = lockFile;
|
||||
|
||||
foreach (location, mLocations)
|
||||
mLocations[location->first] = openAndLock (location->first);
|
||||
{
|
||||
location->pending = openAndLock (location->path + "/pending.data");
|
||||
location->completed = openAndLock (location->path + "/completed.data");
|
||||
}
|
||||
|
||||
mAllOpenAndLocked = true;
|
||||
}
|
||||
|
@ -132,16 +137,18 @@ void TDB::lock (bool lockFile /* = true */)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::unlock ()
|
||||
{
|
||||
foreach (location, mLocations)
|
||||
if (mAllOpenAndLocked)
|
||||
{
|
||||
if (mLocations[location->first] != NULL)
|
||||
foreach (location, mLocations)
|
||||
{
|
||||
fclose (mLocations[location->first]);
|
||||
mLocations[location->first] = NULL;
|
||||
fclose (location->pending);
|
||||
location->pending = NULL;
|
||||
fclose (location->completed);
|
||||
location->completed = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mAllOpenAndLocked = false;
|
||||
mAllOpenAndLocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -151,11 +158,27 @@ int TDB::load (std::vector <T>& tasks, Filter& filter)
|
|||
char line[T_LINE_MAX];
|
||||
foreach (location, mLocations)
|
||||
{
|
||||
std::cout << "# location.path: " << location->path << std::endl;
|
||||
|
||||
while (fgets (line, T_LINE_MAX, location->pending))
|
||||
{
|
||||
int length = ::strlen (line);
|
||||
if (length > 1)
|
||||
{
|
||||
line[length - 1] = '\0'; // Kill \n
|
||||
std::cout << "# line: " << line << std::endl;
|
||||
|
||||
T task (line);
|
||||
|
||||
std::cout << "# location: " << location->first << std::endl;
|
||||
while (fgets (line, T_LINE_MAX, location->second))
|
||||
if (filter.pass (task))
|
||||
{
|
||||
// TODO Add hidden attribute indicating source.
|
||||
tasks.push_back (task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (fgets (line, T_LINE_MAX, location->completed))
|
||||
{
|
||||
int length = ::strlen (line);
|
||||
if (length > 1)
|
||||
|
@ -208,39 +231,6 @@ void TDB::upgrade ()
|
|||
throw std::string ("unimplemented TDB::upgrade");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::getPendingFiles (std::vector <std::string> files)
|
||||
{
|
||||
files.clear ();
|
||||
|
||||
foreach (location, mLocations)
|
||||
files.push_back (location->first + "/pending.data");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::getCompletedFiles (std::vector <std::string> files)
|
||||
{
|
||||
files.clear ();
|
||||
|
||||
foreach (location, mLocations)
|
||||
files.push_back (location->first + "/completed.data");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::getContactFiles (std::vector <std::string> files)
|
||||
{
|
||||
files.clear ();
|
||||
|
||||
foreach (location, mLocations)
|
||||
files.push_back (location->first + "/contact.data");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB::getUndoStack (std::string& file)
|
||||
{
|
||||
throw std::string ("unimplemented TDB::getUndoStack");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
FILE* TDB::openAndLock (const std::string& file)
|
||||
{
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Filter.h"
|
||||
#include "T.h"
|
||||
#include <Location.h>
|
||||
#include <Filter.h>
|
||||
#include <T.h>
|
||||
|
||||
// Length of longest line.
|
||||
#define T_LINE_MAX 32768
|
||||
|
@ -56,14 +57,10 @@ public:
|
|||
void upgrade ();
|
||||
|
||||
private:
|
||||
void getPendingFiles (std::vector <std::string>);
|
||||
void getCompletedFiles (std::vector <std::string>);
|
||||
void getContactFiles (std::vector <std::string>);
|
||||
void getUndoStack (std::string&);
|
||||
FILE* openAndLock (const std::string&);
|
||||
|
||||
private:
|
||||
std::map <std::string, FILE*> mLocations;
|
||||
std::vector <Location> mLocations;
|
||||
bool mLock;
|
||||
bool mAllOpenAndLocked;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue