Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haiku port #7720

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ if(BUILD_CLIENT)
find_package(Sparkle)
endif(APPLE)

if(UNIX AND NOT APPLE)
if(UNIX AND NOT APPLE AND NOT HAIKU)
find_package(Inotify REQUIRED)
endif()
find_package(Sphinx)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if(NOT TOKEN_AUTH_ONLY)
endif()

# TODO: Mingw64 7.3 might also need to be excluded here as it seems to not automatically link libssp
if(NOT WIN32)
if(NOT WIN32 AND NOT HAIKU)
if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "^(alpha|parisc|hppa)") AND NOT CMAKE_CROSSCOMPILING)
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector --param=ssp-buffer-size=4")
Expand Down
6 changes: 5 additions & 1 deletion src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#include "utility_win.cpp"
#elif defined(Q_OS_MAC)
#include "utility_mac.cpp"
#elif defined(Q_OS_HAIKU)
#include "utility_haiku.cpp"
#else
#include "utility_unix.cpp"
#endif
Expand Down Expand Up @@ -169,6 +171,8 @@ static QLatin1String platform()
return QLatin1String("OpenBSD");
#elif defined(Q_OS_SOLARIS)
return QLatin1String("Solaris");
#elif defined(Q_OS_HAIKU)
return QLatin1String("Haiku");
#else
return QSysInfo::productType();
#endif
Expand Down Expand Up @@ -208,7 +212,7 @@ void Utility::setLaunchOnStartup(const QString &appName, const QString &guiName,

qint64 Utility::freeDiskSpace(const QString &path)
{
#if defined(Q_OS_MAC) || defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD)
#if defined(Q_OS_MAC) || defined(Q_OS_FREEBSD) || defined(Q_OS_FREEBSD_KERNEL) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD) || defined(Q_OS_HAIKU)
struct statvfs stat;
if (statvfs(path.toLocal8Bit().data(), &stat) == 0) {
return (qint64)stat.f_bavail * stat.f_frsize;
Expand Down
10 changes: 10 additions & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ namespace Utility {
inline bool isUnix();
inline bool isLinux(); // use with care
inline bool isBSD(); // use with care, does not match OS X
inline bool isHaiku();

OCSYNC_EXPORT QString platformName();
// crash helper for --debug
Expand Down Expand Up @@ -292,5 +293,14 @@ inline bool Utility::isBSD()
#endif
}

inline bool Utility::isHaiku()
{
#if defined(Q_OS_HAIKU)
return true;
#else
return false;
#endif
}

}
#endif // UTILITY_H
79 changes: 79 additions & 0 deletions src/common/utility_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <QDir>
#include <QFile>
#include <QString>

#include <FindDirectory.h>
#include <Path.h>

namespace OCC {

static void setupFavLink_private(const QString &folder)
{
Q_UNUSED(folder);
// Haiku doesn't really have that concept of bookmarks on folders
}

// returns the autostart directory the Haiku way
// should probably use launch_daemon service directly though
// instead of the old way
QString getUserAutostartDir_private()
{
BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
QString config = QString::fromUtf8(path.Path());
config += QLatin1String("/boot/launch/");
return config;
}

bool hasLaunchOnStartup_private(const QString &appName)
{
QString startupFileLocation = getUserAutostartDir_private() + appName;
return QFile::exists(startupFileLocation);
}

void setLaunchOnStartup_private(const QString &appName, const QString &guiName, bool enable)
{
Q_UNUSED(guiName);
QString userAutoStartPath = getUserAutostartDir_private();
QString startupFileLocation = userAutoStartPath + appName;
if (enable) {
if (!QDir().exists(userAutoStartPath) && !QDir().mkpath(userAutoStartPath)) {
qCWarning(lcUtility) << "Could not create autostart folder" << userAutoStartPath;
return;
}
if (!QFile::link(QCoreApplication::applicationFilePath(), startupFileLocation)) {
qCWarning(lcUtility) << "Could not write autostart symlink" << startupFileLocation;
return;
}
} else {
if (!QFile::remove(startupFileLocation)) {
qCWarning(lcUtility) << "Could not remove autostart symlink";
}
}
}

static inline bool hasDarkSystray_private()
{
return true;
}

} // namespace OCC
5 changes: 5 additions & 0 deletions src/csync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ if (APPLE)
target_link_libraries("${csync_NAME}" ${FOUNDATION_LIBRARY} ${CORESERVICES_LIBRARY})
endif()

# For src/common/utility_haiku.cpp
if (HAIKU)
target_link_libraries("${csync_NAME}" be)
endif()

set_target_properties(
"${csync_NAME}"
PROPERTIES
Expand Down
4 changes: 4 additions & 0 deletions src/csync/csync_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#define _GNU_SOURCE
#endif

#ifdef __HAIKU__
#define _BSD_SOURCE
#endif

#include <errno.h>
#include <limits.h>
#include <stdio.h>
Expand Down
9 changes: 8 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ IF( APPLE )
endif()
ENDIF()

IF( NOT WIN32 AND NOT APPLE )
IF( NOT WIN32 AND NOT APPLE AND NOT HAIKU )
list(APPEND client_SRCS folderwatcher_linux.cpp)
ENDIF()
IF( WIN32 )
Expand All @@ -129,6 +129,9 @@ ENDIF()
IF( APPLE )
list(APPEND client_SRCS folderwatcher_mac.cpp)
ENDIF()
IF( HAIKU )
list(APPEND client_SRCS folderwatcher_haiku.cpp)
ENDIF()

set(3rdparty_SRC
../3rdparty/QProgressIndicator/QProgressIndicator.cpp
Expand Down Expand Up @@ -185,6 +188,10 @@ if (APPLE)
target_link_libraries(owncloudCore PUBLIC Qt5::MacExtras)
endif()

if (HAIKU)
target_link_libraries(owncloudCore PUBLIC be)
endif()

if(WITH_CRASHREPORTER)
target_link_libraries(owncloudCore PUBLIC crashreporter-handler)

Expand Down
2 changes: 2 additions & 0 deletions src/gui/folderwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "folderwatcher_win.h"
#elif defined(Q_OS_MAC)
#include "folderwatcher_mac.h"
#elif defined(Q_OS_HAIKU)
#include "folderwatcher_haiku.h"
#elif defined(Q_OS_UNIX)
#include "folderwatcher_linux.h"
#endif
Expand Down
144 changes: 144 additions & 0 deletions src/gui/folderwatcher_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright (C) by François Revol <revol@free.fr>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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.
*/
#include "config.h"

#include "folder.h"
#include "folderwatcher.h"
#include "folderwatcher_haiku.h"


#include <cerrno>
#include <QObject>
#include <QStringList>

#include <Application.h>
#include <Path.h>
#include <String.h>
#include <private/storage/PathMonitor.h>



namespace OCC {


void WatcherHandler::MessageReceived(BMessage* message)
{
qCDebug(lcFolderWatcher) << "WatcherHandler::MessageReceived()" << message->what;
if (message->what != B_PATH_MONITOR) {
BHandler::MessageReceived(message);
return;
}

int32 opcode;
if (message->FindInt32("opcode", &opcode) != B_OK)
return;

const char *path = NULL;
if (message->FindString("path", &path) != B_OK)
return;

// get the filename
// sometimes we have it in the message, but not always
BPath p(path);
BString fileName(p.Leaf());
if (fileName.StartsWith("._sync_")
|| fileName.StartsWith(".csync_journal.db")
|| fileName.StartsWith(".owncloudsync.log")
|| fileName.StartsWith(".sync_")) {
return;
}

int32 fields;
QStringList paths;

switch (opcode) {
case B_ENTRY_MOVED:
{
const char *from = NULL;
if (message->FindString("from path", &from) != B_OK)
return;
QString qFrom = QString::fromUtf8(from);
paths.append(qFrom);
break;
}
case B_ENTRY_CREATED:
case B_ENTRY_REMOVED:
break;
case B_STAT_CHANGED:
if (message->FindInt32("fields", &fields) != B_OK)
return;
// we're only interested in mtime
// and content change... which should always change mtime though
// just to be sure, check size changes as well
if (fields & (B_STAT_MODIFICATION_TIME | B_STAT_SIZE))
break;
return;
case B_ATTR_CHANGED:
// TODO: it is just unacceptable to not handle xattrs on Haiku!
// but it must be done properly,
// cf. http://dcevents.dublincore.org/IntConf/dc-2011/paper/view/53
default:
// discard
return;
}

//message->PrintToStream();

QString qPath = QString::fromUtf8(path);
paths.append(qPath);
emit changed(paths);
}


FolderWatcherPrivate::FolderWatcherPrivate(FolderWatcher *p, const QString &path)
: _parent(p)
, _folder(path)
, _handler(new WatcherHandler)
{
this->startWatching();
}

FolderWatcherPrivate::~FolderWatcherPrivate()
{
BPrivate::BPathMonitor::StopWatching(BMessenger(_handler));
be_app->Lock();
be_app->RemoveHandler(_handler);
be_app->Unlock();
delete _handler;
}

void FolderWatcherPrivate::startWatching()
{
qCDebug(lcFolderWatcher) << "FolderWatcherPrivate::startWatching()" << _folder;

// it needs to be attached to a BLooper, which be_app happens to be.
be_app->Lock();
be_app->AddHandler(_handler);
be_app->Unlock();

connect(_handler, SIGNAL(changed(const QStringList &)),
_parent, SLOT(changeDetected(const QStringList &)));
connect(_handler, SIGNAL(lostChanges()),
_parent, SIGNAL(lostChanges()));

BMessenger messenger(_handler);
uint32 flags = B_WATCH_RECURSIVELY | B_WATCH_NAME | B_WATCH_STAT;
status_t err;
err = BPrivate::BPathMonitor::StartWatching(_folder.toUtf8().constData(), flags, messenger);
if (err != B_OK)
qCWarning(lcFolderWatcher) << "BPathMonitor::StartWatching failed: " << strerror(err);
}


} // ns mirall