Permalink
Browse files

Linux-Fan <Ma_Sys.ma@web.de> - implement -m option.

e commit message for your changes. Lines starting
  • Loading branch information...
svarshavchik committed Mar 30, 2018
1 parent 0855041 commit 8b7c9271d367f66200cca60fecbf5c951f2719c9
Showing with 119 additions and 1 deletion.
  1. +16 −1 cone/cone/cone.C
  2. +20 −0 cone/cone/curseshierarchy.C
  3. +9 −0 cone/cone/curseshierarchy.H
  4. +62 −0 cone/cone/myserver.C
  5. +12 −0 cone/cone/myserver.H
@@ -429,6 +429,7 @@ void openHierarchyScreen(std::string prompt,
myServer **selectedServer)
{
CursesHierarchy hierarchy_screen( &myServer::hierarchy, mainScreen);
myServer::setCursesHierarchyPointerForRefreshing(&hierarchy_screen);
titleBar->setTitles(_("FOLDERS"), "");
@@ -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)
@@ -1025,6 +1028,8 @@ static void cleanup()
delete myServer::remoteConfigAccount;
myServer::remoteConfigAccount=NULL;
}
myServer::closePollForRefreshMessageCount();
}
//
@@ -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':
@@ -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;
@@ -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)
{
@@ -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;
@@ -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,
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <pwd.h>
#include <unistd.h>
#include <poll.h>
#include <iostream>
@@ -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)
@@ -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)
@@ -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();
@@ -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;
}
@@ -14,6 +14,7 @@
#include "curses/timer.H"
#include "myreadfolders.H"
#include "certificates.H"
#include "curseshierarchy.H"
#include <string>
#include <vector>
@@ -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);
@@ -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);

0 comments on commit 8b7c927

Please sign in to comment.