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
|
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 =
|
LFLAGS =
|
||||||
LIBS =
|
LIBS =
|
||||||
OBJECTS = main.o Context.o TDB.o T.o ../Sequence.o ../Filter.o ../Att.o \
|
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 \
|
Keymap.o ../Record.o ../Mod.o ../StringTable.o ../util.o ../text.o \
|
||||||
../Date.o ../Config.o
|
../Date.o ../Config.o Location.o
|
||||||
|
|
||||||
all: $(PROJECT)
|
all: $(PROJECT)
|
||||||
|
|
||||||
|
|
|
@ -73,30 +73,32 @@ TDB::TDB ()
|
||||||
TDB::TDB (const TDB& other)
|
TDB::TDB (const TDB& other)
|
||||||
{
|
{
|
||||||
throw std::string ("unimplemented TDB::TDB");
|
throw std::string ("unimplemented TDB::TDB");
|
||||||
mLocations = other.mLocations;
|
// mLocations = other.mLocations;
|
||||||
mLock = other.mLock;
|
// mFiles = other.mFiles;
|
||||||
mAllOpenAndLocked = false; // Deliberately so.
|
// mLock = other.mLock;
|
||||||
|
// mAllOpenAndLocked = false; // Deliberately so.
|
||||||
// Set all to NULL.
|
//
|
||||||
foreach (location, mLocations)
|
// // Set all to NULL, otherwise we are duplicating open file handles.
|
||||||
mLocations[location->first] = NULL;
|
// foreach (file, mFiles)
|
||||||
|
// mFiles[file->first] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
TDB& TDB::operator= (const TDB& other)
|
TDB& TDB::operator= (const TDB& other)
|
||||||
{
|
{
|
||||||
throw std::string ("unimplemented TDB::operator=");
|
throw std::string ("unimplemented TDB::operator=");
|
||||||
if (this != &other)
|
// if (this != &other)
|
||||||
{
|
// {
|
||||||
mLocations = other.mLocations;
|
// mLocations = other.mLocations;
|
||||||
mLock = other.mLock;
|
// mFiles = other.mFiles;
|
||||||
mAllOpenAndLocked = false; // Deliberately so.
|
// mLock = other.mLock;
|
||||||
|
// mAllOpenAndLocked = false; // Deliberately so.
|
||||||
// Set all to NULL.
|
//
|
||||||
foreach (location, mLocations)
|
// // Set all to NULL, otherwise we are duplicating open file handles.
|
||||||
mLocations[location->first] = NULL;
|
// foreach (file, mFiles)
|
||||||
}
|
// mFiles[file->first] = NULL;
|
||||||
|
// }
|
||||||
|
//
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +117,7 @@ void TDB::location (const std::string& path)
|
||||||
path +
|
path +
|
||||||
"' does not exist, or is not readable and writable.";
|
"' does not exist, or is not readable and writable.";
|
||||||
|
|
||||||
mLocations[path] = NULL;
|
mLocations.push_back (Location (path));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -124,25 +126,30 @@ void TDB::lock (bool lockFile /* = true */)
|
||||||
mLock = lockFile;
|
mLock = lockFile;
|
||||||
|
|
||||||
foreach (location, mLocations)
|
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;
|
mAllOpenAndLocked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TDB::unlock ()
|
void TDB::unlock ()
|
||||||
|
{
|
||||||
|
if (mAllOpenAndLocked)
|
||||||
{
|
{
|
||||||
foreach (location, mLocations)
|
foreach (location, mLocations)
|
||||||
{
|
{
|
||||||
if (mLocations[location->first] != NULL)
|
fclose (location->pending);
|
||||||
{
|
location->pending = NULL;
|
||||||
fclose (mLocations[location->first]);
|
fclose (location->completed);
|
||||||
mLocations[location->first] = NULL;
|
location->completed = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mAllOpenAndLocked = false;
|
mAllOpenAndLocked = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Returns number of filtered tasks.
|
// Returns number of filtered tasks.
|
||||||
|
@ -151,11 +158,27 @@ int TDB::load (std::vector <T>& tasks, Filter& filter)
|
||||||
char line[T_LINE_MAX];
|
char line[T_LINE_MAX];
|
||||||
foreach (location, mLocations)
|
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;
|
if (filter.pass (task))
|
||||||
while (fgets (line, T_LINE_MAX, location->second))
|
{
|
||||||
|
// TODO Add hidden attribute indicating source.
|
||||||
|
tasks.push_back (task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fgets (line, T_LINE_MAX, location->completed))
|
||||||
{
|
{
|
||||||
int length = ::strlen (line);
|
int length = ::strlen (line);
|
||||||
if (length > 1)
|
if (length > 1)
|
||||||
|
@ -208,39 +231,6 @@ void TDB::upgrade ()
|
||||||
throw std::string ("unimplemented 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)
|
FILE* TDB::openAndLock (const std::string& file)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,8 +30,9 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Filter.h"
|
#include <Location.h>
|
||||||
#include "T.h"
|
#include <Filter.h>
|
||||||
|
#include <T.h>
|
||||||
|
|
||||||
// Length of longest line.
|
// Length of longest line.
|
||||||
#define T_LINE_MAX 32768
|
#define T_LINE_MAX 32768
|
||||||
|
@ -56,14 +57,10 @@ public:
|
||||||
void upgrade ();
|
void upgrade ();
|
||||||
|
|
||||||
private:
|
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&);
|
FILE* openAndLock (const std::string&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map <std::string, FILE*> mLocations;
|
std::vector <Location> mLocations;
|
||||||
bool mLock;
|
bool mLock;
|
||||||
bool mAllOpenAndLocked;
|
bool mAllOpenAndLocked;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue