Enable building of ChronoShare.app
Temporarily disable integrated tests
Change-Id: I652e27f1a19dc9f5b3e0b1399e0fe015f61b3e81
diff --git a/gui/chronosharegui.cpp b/gui/chronosharegui.cpp
index 687d14c..3159699 100644
--- a/gui/chronosharegui.cpp
+++ b/gui/chronosharegui.cpp
@@ -49,9 +49,8 @@
ChronoShareGui::ChronoShareGui(QWidget* parent)
: QDialog(parent)
, m_httpServer(0)
-#ifdef SPARKLE_SUPPORTED
- , m_autoUpdate(
- new SparkleAutoUpdate(tr("http://irl.cs.ucla.edu/~zhenkai/chronoshare_dist/chronoshare.xml")))
+#ifdef AUTOUPDATE
+ , m_sparkle(CHRONOSHARE_APPCAST)
#endif
{
setWindowTitle("Settings");
@@ -128,6 +127,9 @@
, m_dirPath(dirPath)
, m_username(username)
, m_sharedFolderName(sharedFolderName)
+#ifdef AUTOUPDATE
+ , m_sparkle(CHRONOSHARE_APPCAST)
+#endif
{
if (m_username.isNull() || m_username == "" || m_sharedFolderName.isNull() ||
m_sharedFolderName == "" || m_dirPath.isNull() || m_dirPath == "") {
@@ -243,10 +245,7 @@
// cleanup
delete m_trayIcon;
delete m_trayIconMenu;
-#ifdef SPARKLE_SUPPORTED
- delete m_autoUpdate;
- delete m_checkForUpdates;
-#endif
+
delete m_openFolder;
delete m_viewSettings;
delete m_changeFolder;
@@ -259,9 +258,6 @@
delete button;
delete label;
delete mainLayout;
-
- // to avoid `private field 'm_checkForUpdates' is not used` warning/error
- (void)(m_checkForUpdates);
}
void
@@ -332,10 +328,10 @@
m_changeFolder = new QAction(tr("&Change Folder"), this);
connect(m_changeFolder, SIGNAL(triggered()), this, SLOT(openFileDialog()));
-#ifdef SPARKLE_SUPPORTED
- m_checkForUpdates = new QAction(tr("Check For Updates"), this);
- connect(m_checkForUpdates, SIGNAL(triggered()), this, SLOT(onCheckForUpdates()));
-#endif
+#ifdef AUTOUPDATE
+ m_checkForUpdates = new QAction("Check for updates", this);
+ connect(m_checkForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates()));
+#endif // AUTOUPDATE
// create the "quit program" action
m_quitProgram = new QAction(tr("&Quit"), this);
@@ -356,10 +352,10 @@
m_trayIconMenu->addAction(m_viewSettings);
m_trayIconMenu->addAction(m_changeFolder);
-#ifdef SPARKLE_SUPPORTED
+#ifdef AUTOUPDATE
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_checkForUpdates);
-#endif
+#endif // AUTOUPDATE
m_trayIconMenu->addSeparator();
m_trayIconMenu->addAction(m_quitProgram);
@@ -376,16 +372,6 @@
}
void
-ChronoShareGui::onCheckForUpdates()
-{
-#ifdef SPARKLE_SUPPORTED
- cout << "+++++++++++ trying to update +++++++ " << endl;
- m_autoUpdate->checkForUpdates();
- cout << "+++++++++++ end trying to update +++++++ " << endl;
-#endif
-}
-
-void
ChronoShareGui::setIcon()
{
// set the icon image
@@ -598,7 +584,9 @@
// Load Settings
// QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
- QSettings settings(QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
+ QSettings settings;
+
+ _LOG_DEBUG("load settings");
if (settings.contains("username")) {
m_username = settings.value("username", "admin").toString();
@@ -637,7 +625,7 @@
{
// Save Settings
// QSettings settings(m_settingsFilePath, QSettings::NativeFormat);
- QSettings settings(QSettings::NativeFormat, QSettings::UserScope, "irl.cs.ucla.edu", "ChronoShare");
+ QSettings settings;
settings.setValue("dirPath", m_dirPath);
settings.setValue("username", m_username);
@@ -660,6 +648,14 @@
event->ignore(); // don't let the event propagate to the base class
}
+#ifdef AUTOUPDATE
+void
+ChronoShareGui::checkForUpdates()
+{
+ m_sparkle.checkForUpdates();
+}
+#endif // AUTOUPDATE
+
} // namespace chronoshare
} // namespace ndn
diff --git a/gui/chronosharegui.hpp b/gui/chronosharegui.hpp
index c23fcf9..d80e8f6 100644
--- a/gui/chronosharegui.hpp
+++ b/gui/chronosharegui.hpp
@@ -42,13 +42,12 @@
#include "server.hpp"
#endif // Q_MOC_RUN
-#if __APPLE__ && HAVE_SPARKLE
-#define SPARKLE_SUPPORTED 1
-#include "sparkle-auto-update.hpp"
-#endif
-
#include <thread>
+#ifdef AUTOUPDATE
+#include "osx-auto-update-sparkle.hpp"
+#endif // AUTOUPDATE
+
namespace ndn {
namespace chronoshare {
@@ -105,8 +104,10 @@
void
changeSettings();
+#ifdef AUTOUPDATE
void
- onCheckForUpdates();
+ checkForUpdates();
+#endif // AUTOUPDATE
private:
void
@@ -158,7 +159,6 @@
QAction* m_viewSettings; // chronoShare settings
QAction* m_changeFolder; // change the shared folder action
QAction* m_quitProgram; // quit program action
- QAction* m_checkForUpdates;
QAction* m_openWeb;
QMenu* m_recentFilesMenu;
QAction* m_fileActions[5];
@@ -181,9 +181,6 @@
QLabel* label;
QVBoxLayout* mainLayout;
-#ifdef SPARKLE_SUPPORTED
- AutoUpdate* m_autoUpdate;
-#endif
// QString m_settingsFilePath; // settings file path
// QString m_settings;
@@ -194,6 +191,11 @@
std::unique_ptr<Face> m_face;
std::unique_ptr<FsWatcher> m_watcher;
std::unique_ptr<Dispatcher> m_dispatcher;
+
+#ifdef AUTOUPDATE
+ QAction* m_checkForUpdates;
+ OsxAutoUpdateSparkle m_sparkle;
+#endif // AUTOUPDATE
};
} // namespace chronoshare
diff --git a/gui/osx-auto-update-sparkle.hpp b/gui/osx-auto-update-sparkle.hpp
new file mode 100644
index 0000000..bf2bfa7
--- /dev/null
+++ b/gui/osx-auto-update-sparkle.hpp
@@ -0,0 +1,54 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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 3 of the License, or (at your option) any later version.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#ifndef NCC_OSX_AUTO_UPDATE_SPARKLE_HPP
+#define NCC_OSX_AUTO_UPDATE_SPARKLE_HPP
+
+#include "core/chronoshare-config.hpp"
+
+#ifndef OSX_BUILD
+#error "Cannot be included for non-OSX build"
+#endif // OSX_BUILD
+
+#include <string>
+#include <ndn-cxx/util/backports.hpp>
+
+namespace ndn {
+namespace chronoshare {
+
+class OsxAutoUpdateSparkle
+{
+public:
+ OsxAutoUpdateSparkle(const std::string& updateUrl);
+
+ ~OsxAutoUpdateSparkle();
+
+ void
+ checkForUpdates();
+
+private:
+ class Impl;
+ unique_ptr<Impl> m_impl;
+};
+
+} // namespace chronoshare
+} // namespace ndn
+
+#endif // NCC_OSX_AUTO_UPDATE_SPARKLE_HPP
diff --git a/gui/osx-auto-update-sparkle.mm b/gui/osx-auto-update-sparkle.mm
new file mode 100644
index 0000000..e3e3c3e
--- /dev/null
+++ b/gui/osx-auto-update-sparkle.mm
@@ -0,0 +1,61 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare 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 3 of the License, or (at your option) any later version.
+ *
+ * ChronoShare 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 copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#include "osx-auto-update-sparkle.hpp"
+
+#import <AppKit/AppKit.h>
+#import <Foundation/Foundation.h>
+#import <Sparkle/Sparkle.h>
+
+namespace ndn {
+namespace chronoshare {
+
+class OsxAutoUpdateSparkle::Impl
+{
+public:
+ SUUpdater* m_updater;
+};
+
+
+OsxAutoUpdateSparkle::OsxAutoUpdateSparkle(const std::string& updateUrl)
+ : m_impl(make_unique<Impl>())
+{
+ m_impl->m_updater = [[SUUpdater sharedUpdater] retain];
+ NSURL* url = [NSURL URLWithString:[NSString stringWithUTF8String:updateUrl.data()]];
+ [m_impl->m_updater setFeedURL:url];
+ [m_impl->m_updater setAutomaticallyChecksForUpdates:YES];
+ [m_impl->m_updater setUpdateCheckInterval:86400];
+}
+
+OsxAutoUpdateSparkle::~OsxAutoUpdateSparkle()
+{
+ [m_impl->m_updater release];
+ // presummably SUUpdater handles garbage collection
+}
+
+void
+OsxAutoUpdateSparkle::checkForUpdates()
+{
+ //[m_impl->m_updater checkForUpdatesInBackground];
+ [m_impl->m_updater checkForUpdates:nil];
+}
+
+} // namespace chronoshare
+} // namespace ndn