Skip to content

Commit

Permalink
Few notification improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaonex86 committed Feb 23, 2018
1 parent 1bb23f1 commit 6414ec1
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 40 deletions.
18 changes: 13 additions & 5 deletions CliParser.cpp
Expand Up @@ -5,12 +5,14 @@

#include "CliParser.h"
#include "cpp11addition.h"
#include "Core.h"

#include <QDebug>

CliParser::CliParser(QObject *parent) :
QObject(parent)
{
//this->core=core;
}

/** \brief method to parse the ultracopier arguments
Expand All @@ -24,11 +26,17 @@ void CliParser::cli(const std::vector<std::string> &ultracopierArguments,const b
{
if(external)
{
#ifdef Q_OS_WIN32
QMessageBox::warning(NULL,tr("Warning"),tr("Ultracopier is already running, right click on its system tray icon (near the clock) to use it or just copy and paste"));
#else
QMessageBox::warning(NULL,tr("Warning"),tr("Ultracopier is already running, view all notification area icons (near the clock), right click on its system tray icon to use it or just copy and paste"));
#endif
//if(!core->startNewTransferOneUniqueCopyEngine())
{
#ifdef Q_OS_WIN32
QString message(tr("Ultracopier is already running, right click on its system tray icon (near the clock) to use it or just copy and paste"));
#else
QString message(tr("Ultracopier is already running, view all notification area icons (near the clock), right click on its system tray icon to use it or just copy and paste"));
#endif

QMessageBox::warning(NULL,tr("Warning"),message);
showSystrayMessage(message.toStdString());
}
}
// else do nothing, is normal starting without arguements
return;
Expand Down
8 changes: 7 additions & 1 deletion CliParser.h
Expand Up @@ -13,12 +13,13 @@

#include "Environment.h"

class Core;
/** \brief class to parse all command line options */
class CliParser : public QObject
{
Q_OBJECT
public:
explicit CliParser(QObject *parent = 0);
explicit CliParser(/*Core *core,*/QObject *parent = 0);
public slots:
/** \brief method to parse the ultracopier arguments
\param ultracopierArguments the argument list
Expand All @@ -40,10 +41,15 @@ public slots:
void tryLoadPlugin(const std::string &file) const;
/// \brief Show the help option
void showOptions() const;

/// \brief For show a message linked to the systray icon
void showSystrayMessage(const std::string& text);
private:
/** \brief show the help
*\param incorrectArguments if the help is call because the arguments are wrong */
void showHelp(const bool &incorrectArguments=true);

//Core *core;
};

#endif // CLIPARSER_H
5 changes: 3 additions & 2 deletions CopyEngineManager.cpp
Expand Up @@ -177,7 +177,8 @@ void CopyEngineManager::onePluginWillBeUnloaded(const PluginsAvailable &plugin)
}
#endif

CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const Ultracopier::CopyMode &mode,const std::vector<std::string> &protocolsUsedForTheSources,const std::string &protocolsUsedForTheDestination)
CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const Ultracopier::CopyMode &mode,
const std::vector<std::string> &protocolsUsedForTheSources,const std::string &protocolsUsedForTheDestination)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, pluginList.size(): "+std::to_string(pluginList.size())+", mode: "+std::to_string((int)mode)+", and particular protocol");
returnCopyEngine temp;
Expand Down Expand Up @@ -251,7 +252,7 @@ CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const Ultra
while(index<pluginList.size())
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"Check matching: "+pluginList.at(index).name);
if(pluginList.at(index).name==name)
if(pluginList.at(index).name==name || name.empty())
{
if(mode==Ultracopier::Move && pluginList.at(index).canDoOnlyCopy)
{
Expand Down
17 changes: 16 additions & 1 deletion Core.cpp
Expand Up @@ -220,6 +220,20 @@ void Core::newTransferList(std::string engine,std::string mode,std::string file)
copyList.back().engine->newTransferList(file);
}

bool Core::startNewTransferOneUniqueCopyEngine()
{
if(copyList.size()!=1)
return false;

if(openNewCopyEngineInstance(Ultracopier::Copy,true,std::string())==-1)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Unable to get a copy engine instance");
QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
return false;
}
return true;
}

void Core::loadInterface()
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start");
Expand Down Expand Up @@ -287,7 +301,8 @@ unsigned int Core::incrementId()
\param protocolsUsedForTheSources protocols used for sources
\param protocolsUsedForTheDestination protocols used for destination
*/
int Core::openNewCopyEngineInstance(const Ultracopier::CopyMode &mode,const bool &ignoreMode,const std::vector<std::string> &protocolsUsedForTheSources,const std::string &protocolsUsedForTheDestination)
int Core::openNewCopyEngineInstance(const Ultracopier::CopyMode &mode,const bool &ignoreMode,
const std::vector<std::string> &protocolsUsedForTheSources,const std::string &protocolsUsedForTheDestination)
{
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start");
CopyEngineManager::returnCopyEngine returnInformations=copyEngineList->getCopyEngine(mode,protocolsUsedForTheSources,protocolsUsedForTheDestination);
Expand Down
5 changes: 3 additions & 2 deletions Core.h
Expand Up @@ -97,8 +97,7 @@ class Core : public QObject
/** open with specific copy engine
\param move Copy or move
\param ignoreMode if need ignore the mode
\param protocolsUsedForTheSources protocols used for sources
\param protocolsUsedForTheDestination protocols used for destination
\param name protocols used for sources
*/
int openNewCopyEngineInstance(const Ultracopier::CopyMode &mode,const bool &ignoreMode,const std::string &name);

Expand Down Expand Up @@ -150,6 +149,8 @@ class Core : public QObject
void addWindowTransfer(const std::string &name);
/** new transfer list pased by the CLI */
void newTransferList(std::string engine,std::string mode,std::string file);

bool startNewTransferOneUniqueCopyEngine();
private slots:
/// \brief the copy engine have canceled the transfer
void copyInstanceCanceledByEngine();
Expand Down
177 changes: 148 additions & 29 deletions EventDispatcher.cpp
Expand Up @@ -7,6 +7,7 @@
#include <QMessageBox>
#include <QWidget>
#include <QStorageInfo>
#include <iostream>

#include "EventDispatcher.h"
#include "ExtraSocket.h"
Expand Down Expand Up @@ -55,15 +56,47 @@ EventDispatcher::EventDispatcher()
qRegisterMetaType<std::vector<std::string> >("std::vector<std::string>");

copyServer=new CopyListener(&optionDialog);
connect(&localListener, &LocalListener::cli, &cliParser, &CliParser::cli,Qt::QueuedConnection);
connect(ThemesManager::themesManager, &ThemesManager::newThemeOptions, &optionDialog, &OptionDialog::newThemeOptions);
connect(&cliParser, &CliParser::newCopyWithoutDestination, copyServer, &CopyListener::copyWithoutDestination);
connect(&cliParser, &CliParser::newCopy, copyServer, &CopyListener::copy);
connect(&cliParser, &CliParser::newMoveWithoutDestination, copyServer, &CopyListener::moveWithoutDestination);
connect(&cliParser, &CliParser::newMove, copyServer, &CopyListener::move);
connect(copyServer, &CopyListener::newClientList, &optionDialog, &OptionDialog::newClientList);
if(!connect(&localListener, &LocalListener::cli, &cliParser, &CliParser::cli,Qt::QueuedConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(ThemesManager::themesManager, &ThemesManager::newThemeOptions, &optionDialog, &OptionDialog::newThemeOptions))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(&cliParser, &CliParser::newCopyWithoutDestination, copyServer, &CopyListener::copyWithoutDestination))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(&cliParser, &CliParser::newCopy, copyServer, &CopyListener::copy))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(&cliParser, &CliParser::newMoveWithoutDestination, copyServer, &CopyListener::moveWithoutDestination))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(&cliParser, &CliParser::newMove, copyServer, &CopyListener::move))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyServer, &CopyListener::newClientList, &optionDialog, &OptionDialog::newClientList))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
#ifdef ULTRACOPIER_PLUGIN_IMPORT_SUPPORT
connect(&cliParser, &CliParser::tryLoadPlugin, PluginsManager::pluginsManager, &PluginsManager::tryLoadPlugin);
if(!connect(&cliParser, &CliParser::tryLoadPlugin, PluginsManager::pluginsManager, &PluginsManager::tryLoadPlugin))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
#endif
copyMoveEventIdIndex=0;
backgroundIcon=NULL;
Expand Down Expand Up @@ -234,12 +267,36 @@ void EventDispatcher::initFunction()
return;
}
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"Initialize the variable of event loop");
connect(copyServer, &CopyListener::newCopyWithoutDestination, core, &Core::newCopyWithoutDestination,Qt::DirectConnection);
connect(copyServer, &CopyListener::newCopy, core, &Core::newCopy,Qt::DirectConnection);
connect(copyServer, &CopyListener::newMoveWithoutDestination, core, &Core::newMoveWithoutDestination,Qt::DirectConnection);
connect(copyServer, &CopyListener::newMove, core, &Core::newMove,Qt::DirectConnection);
connect(core, &Core::copyFinished, copyServer, &CopyListener::copyFinished,Qt::DirectConnection);
connect(core, &Core::copyCanceled, copyServer, &CopyListener::copyCanceled,Qt::DirectConnection);
if(!connect(copyServer, &CopyListener::newCopyWithoutDestination, core, &Core::newCopyWithoutDestination,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyServer, &CopyListener::newCopy, core, &Core::newCopy,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyServer, &CopyListener::newMoveWithoutDestination, core, &Core::newMoveWithoutDestination,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyServer, &CopyListener::newMove, core, &Core::newMove,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(core, &Core::copyFinished, copyServer, &CopyListener::copyFinished,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(core, &Core::copyCanceled, copyServer, &CopyListener::copyCanceled,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(localListener.tryConnect())
{
stopIt=true;
Expand All @@ -254,36 +311,98 @@ void EventDispatcher::initFunction()
//connect the slot
//quit is for this object
// connect(core, &Core::newCanDoOnlyCopy, backgroundIcon, &SystrayIcon::newCanDoOnlyCopy,Qt::DirectConnection);
connect(backgroundIcon, &SystrayIcon::quit,this,&EventDispatcher::quit);
if(!connect(backgroundIcon, &SystrayIcon::quit,this,&EventDispatcher::quit))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
//show option is for OptionEngine object
connect(backgroundIcon, &SystrayIcon::showOptions, &optionDialog, &OptionDialog::show,Qt::DirectConnection);
connect(&cliParser, &CliParser::showOptions, &optionDialog, &OptionDialog::show,Qt::DirectConnection);
connect(copyServer, &CopyListener::listenerReady, backgroundIcon, &SystrayIcon::listenerReady,Qt::DirectConnection);
connect(copyServer, &CopyListener::pluginLoaderReady, backgroundIcon, &SystrayIcon::pluginLoaderReady,Qt::DirectConnection);
connect(backgroundIcon, &SystrayIcon::tryCatchCopy, copyServer, &CopyListener::listen,Qt::DirectConnection);
connect(backgroundIcon, &SystrayIcon::tryUncatchCopy, copyServer, &CopyListener::close,Qt::DirectConnection);
if(!connect(backgroundIcon, &SystrayIcon::showOptions, &optionDialog, &OptionDialog::show,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(&cliParser, &CliParser::showOptions, &optionDialog, &OptionDialog::show,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyServer, &CopyListener::listenerReady, backgroundIcon, &SystrayIcon::listenerReady,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyServer, &CopyListener::pluginLoaderReady, backgroundIcon, &SystrayIcon::pluginLoaderReady,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(backgroundIcon, &SystrayIcon::tryCatchCopy, copyServer, &CopyListener::listen,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(backgroundIcon, &SystrayIcon::tryUncatchCopy, copyServer, &CopyListener::close,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(stringtobool(OptionEngine::optionEngine->getOptionValue("CopyListener","CatchCopyAsDefault")))
copyServer->listen();
ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"copyServer.oneListenerIsLoaded(): "+std::to_string(copyServer->oneListenerIsLoaded()));
//backgroundIcon->readyToListen(copyServer.oneListenerIsLoaded());

#ifdef ULTRACOPIER_DEBUG
connect(backgroundIcon, &SystrayIcon::saveBugReport, DebugEngine::debugEngine, &DebugEngine::saveBugReport,Qt::QueuedConnection);
if(!connect(backgroundIcon, &SystrayIcon::saveBugReport, DebugEngine::debugEngine, &DebugEngine::saveBugReport,Qt::QueuedConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
#endif
connect(backgroundIcon, &SystrayIcon::addWindowCopyMove, core, &Core::addWindowCopyMove,Qt::DirectConnection);
connect(backgroundIcon, &SystrayIcon::addWindowTransfer, core, &Core::addWindowTransfer,Qt::DirectConnection);
connect(copyEngineList, &CopyEngineManager::addCopyEngine, backgroundIcon, &SystrayIcon::addCopyEngine,Qt::DirectConnection);
connect(copyEngineList, &CopyEngineManager::removeCopyEngine, backgroundIcon, &SystrayIcon::removeCopyEngine,Qt::DirectConnection);
if(!connect(backgroundIcon, &SystrayIcon::addWindowCopyMove, core, &Core::addWindowCopyMove,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(backgroundIcon, &SystrayIcon::addWindowTransfer, core, &Core::addWindowTransfer,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyEngineList, &CopyEngineManager::addCopyEngine, backgroundIcon, &SystrayIcon::addCopyEngine,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
if(!connect(copyEngineList, &CopyEngineManager::removeCopyEngine, backgroundIcon, &SystrayIcon::removeCopyEngine,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
#ifdef ULTRACOPIER_INTERNET_SUPPORT
connect(&internetUpdater,&InternetUpdater::newUpdate, backgroundIcon, &SystrayIcon::newUpdate);
if(!connect(&internetUpdater,&InternetUpdater::newUpdate, backgroundIcon, &SystrayIcon::newUpdate))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
#endif
copyEngineList->setIsConnected();
copyServer->resendState();

connect(&cliParser, &CliParser::showSystrayMessage, backgroundIcon,&SystrayIcon::showSystrayMessage,Qt::QueuedConnection);
}
//conntect the last chance signal before quit
connect(QCoreApplication::instance(),&QCoreApplication::aboutToQuit,this,&EventDispatcher::quit,Qt::DirectConnection);
if(!connect(QCoreApplication::instance(),&QCoreApplication::aboutToQuit,this,&EventDispatcher::quit,Qt::DirectConnection))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
//connect the slot for the help dialog
connect(backgroundIcon,&SystrayIcon::showHelp,&theHelp,&HelpDialog::show);
if(!connect(backgroundIcon,&SystrayIcon::showHelp,&theHelp,&HelpDialog::show))
{
std::cerr << "connect error at " << __FILE__ << ":" << std::to_string(__LINE__) << std::endl;
abort();
}
#ifdef ULTRACOPIER_DEBUG
DebugModel::debugModel->setupTheTimer();
#endif
Expand Down

0 comments on commit 6414ec1

Please sign in to comment.