Add an old-school ASCII-art version of the update dialog as a fallback under Linux when GTK is not available.

If the GTK UI cannot be loaded, this will pop up a terminal displaying
progress information.  Hopefully users will find this mildly amusing.
This commit is contained in:
Robert Knight 2011-08-26 17:36:22 +01:00
parent 630d64e859
commit 9391fb6b5e
4 changed files with 94 additions and 2 deletions

View File

@ -49,6 +49,11 @@ set (HEADERS
UpdaterOptions.h
)
if (UNIX)
set(HEADERS ${HEADERS} UpdateDialogAscii.h)
set(SOURCES ${SOURCES} UpdateDialogAscii.cpp)
endif()
if (ENABLE_GTK)
# embed the GTK helper library into the updater binary.
# At runtime it will be extracted and loaded if the

57
src/UpdateDialogAscii.cpp Normal file
View File

@ -0,0 +1,57 @@
#include "UpdateDialogAscii.h"
#include "ProcessUtils.h"
#include "StringUtils.h"
const char* introMessage =
"Mendeley Updater (ASCII-art edition)\n"
"====================================\n"
"\n"
"We have a nice graphical interface for the Mendeley Updater, but unfortunately\n"
"we can't show it to you :(\n"
"\n"
"You can fix this by installing the GTK 2 libraries.\n\n"
"Installing Updates...\n";
void UpdateDialogAscii::init()
{
const char* path = "/tmp/update-progress";
m_output.open(path);
m_output << introMessage;
std::string command = "xterm";
std::list<std::string> args;
args.push_back("-hold");
args.push_back("-T");
args.push_back("Mendeley Updater");
args.push_back("-e");
args.push_back("tail");
args.push_back("-n+1");
args.push_back("-f");
args.push_back(path);
ProcessUtils::runAsync(command,args);
}
void UpdateDialogAscii::updateError(const std::string& errorMessage)
{
m_mutex.lock();
m_output << "\nThere was a problem installing the update: " << errorMessage << std::endl;
m_mutex.unlock();
}
void UpdateDialogAscii::updateProgress(int percentage)
{
m_mutex.lock();
m_output << "Update Progress: " << intToStr(percentage) << '%' << std::endl;
m_mutex.unlock();
}
void UpdateDialogAscii::updateFinished()
{
m_mutex.lock();
m_output << "\nUpdate Finished. You can now restart Mendeley Desktop." << std::endl;
m_mutex.unlock();
}

21
src/UpdateDialogAscii.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include "UpdateObserver.h"
#include <fstream>
#include "tinythread.h"
class UpdateDialogAscii : public UpdateObserver
{
public:
void init();
virtual void updateError(const std::string& errorMessage);
virtual void updateProgress(int percentage);
virtual void updateFinished();
private:
tthread::mutex m_mutex;
std::ofstream m_output;
};

View File

@ -7,8 +7,11 @@
#include "tinythread.h"
#if defined(PLATFORM_LINUX) and defined(ENABLE_GTK)
#include "UpdateDialogGtkWrapper.h"
#if defined(PLATFORM_LINUX)
#if defined(ENABLE_GTK)
#include "UpdateDialogGtkWrapper.h"
#endif
#include "UpdateDialogAscii.h"
#endif
#if defined(PLATFORM_MAC)
@ -88,12 +91,18 @@ int main(int argc, char** argv)
void runWithUi(int argc, char** argv, UpdateInstaller* installer)
{
#ifdef ENABLE_GTK
UpdateDialogAscii asciiDialog;
UpdateDialogGtkWrapper dialog;
bool useGtk = dialog.init(argc,argv);
if (useGtk)
{
installer->setObserver(&dialog);
}
else
{
asciiDialog.init();
installer->setObserver(&asciiDialog);
}
tthread::thread updaterThread(runUpdaterThread,installer);
if (useGtk)
{