Skip to content

Commit

Permalink
Linux-Fan <Ma_Sys.ma@web.de> - implement -m option.
Browse files Browse the repository at this point in the history
e commit message for your changes. Lines starting
  • Loading branch information
svarshavchik committed Mar 30, 2018
1 parent 0855041 commit 8b7c927
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cone/cone/cone.C
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ void openHierarchyScreen(std::string prompt,
myServer **selectedServer)
{
CursesHierarchy hierarchy_screen( &myServer::hierarchy, mainScreen);
myServer::setCursesHierarchyPointerForRefreshing(&hierarchy_screen);

titleBar->setTitles(_("FOLDERS"), "");

Expand Down Expand Up @@ -474,6 +475,8 @@ void openHierarchyScreen(std::string prompt,
*selectedFolder=hierarchy_screen.folderSelected;
if (selectedServer)
*selectedServer=hierarchy_screen.serverSelected;

myServer::setCursesHierarchyPointerForRefreshing(NULL);
}

void hierarchyScreen(void *dummy)
Expand Down Expand Up @@ -1025,6 +1028,8 @@ static void cleanup()
delete myServer::remoteConfigAccount;
myServer::remoteConfigAccount=NULL;
}

myServer::closePollForRefreshMessageCount();
}

//
Expand Down Expand Up @@ -1142,7 +1147,7 @@ int main(int argc, char *argv[])
int recover=0;
Macros macroBuffer;

while ((optc=getopt(argc, argv, "vrCc:")) != -1)
while ((optc=getopt(argc, argv, "vrCc:m:")) != -1)
{
switch (optc) {
case 'v':
Expand All @@ -1151,6 +1156,16 @@ int main(int argc, char *argv[])
case 'r':
recover=1;
break;
case 'm':
// try to delete if existent, ignore fail
unlink(optarg);
if(mkfifo(optarg, 0644) < 0)
{
perror("Failed to create FIFO");
exit(1);
}
myServer::setPollForRefreshMessageCount(optarg);
break;
case 'c':

myServer::configDir=optarg;
Expand Down
20 changes: 20 additions & 0 deletions cone/cone/curseshierarchy.C
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,26 @@ void CursesHierarchyDeleteFolderVerifyCallback
me->processDeletedFolder(parent, deleted, updatedFolder);
}

bool CursesHierarchy::RefreshIterator::visit(Hierarchy::Folder* f)
{
if(f != NULL && this->cs != NULL)
f->updateInfo(this->cs, true);
return true;
}

bool CursesHierarchy::RefreshIterator::visit(Hierarchy::Server* s)
{
if(s != NULL)
this->cs = s->getServer();
return true;
}

void CursesHierarchy::refreshAllFolders()
{
RefreshIterator iterator;
getHierarchy()->root.prefixIterate(iterator);
}

///////////
bool CursesHierarchy::processKey(const Curses::Key &key)
{
Expand Down
9 changes: 9 additions & 0 deletions cone/cone/curseshierarchy.H
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class CursesHierarchy : public Curses, public HierarchyDisplay,

};

class RefreshIterator: public Hierarchy::EntryIterator {
private:
myServer* cs = NULL;
public:
bool visit(Hierarchy::Folder* f);
bool visit(Hierarchy::Server* s);
};

public:
friend class DrawIterator;

Expand All @@ -84,6 +92,7 @@ public:
bool drawErase(Hierarchy::Server *server, bool doErase);
void visible(Hierarchy::Entry *e);

void refreshAllFolders();

private:
bool drawErase(std::string str1, int col1,
Expand Down
62 changes: 62 additions & 0 deletions cone/cone/myserver.C
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <fcntl.h>
#include <pwd.h>
#include <unistd.h>
#include <poll.h>

#include <iostream>

Expand All @@ -42,6 +43,10 @@ Certificates *myServer::certs;
extern void folderIndexScreen(void *);
extern void hierarchyScreen(void *);

int myServer::pollFDForRefreshMessageCount = -1;
int myServer::pollFDForRefreshMessageCountWriteDirection = -1;
CursesHierarchy* myServer::cursesHierarchyForRefreshing = NULL;

myServer::myServer(string name, string urlArg)
: serverName(name), url(urlArg), mailCheckInterval(300), server(NULL),
currentFolder(NULL), hierarchyEntry(NULL)
Expand Down Expand Up @@ -273,6 +278,16 @@ bool myServer::eventloop(myServer::Callback *callback)
if (alarmCalled)
continue; // Something might've happened...

// poll() ignores file descriptors less than 0, thus the
// `pollFDForRefresh` can always be added regardless of the
// feature being used or not.
struct pollfd pollFDForRefresh = {
myServer::pollFDForRefreshMessageCount,
POLLIN,
0
};
fds.push_back(pollFDForRefresh);

if (mail::account::poll(fds, ioTimeout) < 0)
{
if (errno != EINTR)
Expand All @@ -281,6 +296,17 @@ bool myServer::eventloop(myServer::Callback *callback)
break;
}
}

char buf[128];
int pollev = fds.back().revents;
fds.pop_back();
if((pollev & POLLIN) && read(
myServer::pollFDForRefreshMessageCount,
buf, sizeof(buf)) > 0 &&
myServer::pollFDForRefreshMessageCount != -1 &&
myServer::cursesHierarchyForRefreshing != NULL)
myServer::cursesHierarchyForRefreshing->
refreshAllFolders();
}

statusBar->notbusy();
Expand Down Expand Up @@ -1032,3 +1058,39 @@ void myServer::checkNewMail()

finishCheckingNewMail();
}

void myServer::setPollForRefreshMessageCount(string fn)
{
if((myServer::pollFDForRefreshMessageCount =
open(fn.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK)) < 0)
{
perror("Failed to open FIFO for reading");
exit(1);
}
// Open another file descriptor for writing such that the pipe is
// kept open regardless of any external application closing it.
if((myServer::pollFDForRefreshMessageCountWriteDirection =
open(fn.c_str(), O_WRONLY | O_CLOEXEC)) < 0)
{
perror("Failed to open FIFO for writing");
exit(1);
}
}

void myServer::closePollForRefreshMessageCount()
{
if(myServer::pollFDForRefreshMessageCount != -1)
{
// POSIX logic: close returns 0 on success thus true on fail...
if(close(myServer::pollFDForRefreshMessageCount))
perror("Failed to close message count update file "
"descriptor");
close(myServer::pollFDForRefreshMessageCountWriteDirection);
myServer::pollFDForRefreshMessageCount = -1;
}
}

void myServer::setCursesHierarchyPointerForRefreshing(CursesHierarchy* h)
{
myServer::cursesHierarchyForRefreshing = h;
}
12 changes: 12 additions & 0 deletions cone/cone/myserver.H
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "curses/timer.H"
#include "myreadfolders.H"
#include "certificates.H"
#include "curseshierarchy.H"

#include <string>
#include <vector>
Expand Down Expand Up @@ -86,6 +87,13 @@ private:
std::map<std::string, std::map<std::string, std::string>
> folder_configuration;

// Allow refreshing message counts through messages on a named pipe.
// Necessary file descriptor for reading, the other direction to keep
// the pipe open and GUI pointer.
static int pollFDForRefreshMessageCount;
static int pollFDForRefreshMessageCountWriteDirection;
static CursesHierarchy* cursesHierarchyForRefreshing;

public:
bool updateServerConfiguration(std::string name, std::string value);
std::string getServerConfiguration(std::string name);
Expand Down Expand Up @@ -220,6 +228,10 @@ public:
void addHierarchy(bool assignRows);
void showHierarchy();
void updateHierarchy();

static void setPollForRefreshMessageCount(std::string fn);
static void closePollForRefreshMessageCount();
static void setCursesHierarchyPointerForRefreshing(CursesHierarchy* h);
private:
void addTopLevelFolders();
void addTopLevelFolder(std::string);
Expand Down

0 comments on commit 8b7c927

Please sign in to comment.