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

Add SocketApi for file manager integration #42

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
CMakeLists.txt.user*
*.patch
doc/_build/*
*~
*.kate-swp
*.kdev4
win/
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ project(mirall)
set(PACKAGE "mirall")
set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules )


option(ENABLE_SOCKETAPI "Enable SocketApi needed for file manager integration" OFF)


if ( EXISTS ${CMAKE_SOURCE_DIR}/OEM.cmake )
include ( ${CMAKE_SOURCE_DIR}/OEM.cmake )
else ()
Expand Down Expand Up @@ -40,6 +44,7 @@ endif()
find_package(Qt4 4.6.0 COMPONENTS QtCore QtGui QtXml QtNetwork QtTest REQUIRED )
find_package(Csync)
find_package(INotify)
find_package(LibAttica)

set(WITH_CSYNC CSYNC_FOUND)
set(USE_INOTIFY ${INOTIFY_FOUND})
Expand Down
63 changes: 63 additions & 0 deletions cmake/modules/FindLibAttica.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Try to find the Attica library
# Once done this will define
#
# LIBATTICA_FOUND Indicates that Attica was found
# LIBATTICA_LIBRARIES Libraries needed to use Attica
# LIBATTICA_LIBRARY_DIRS Paths needed for linking against Attica
# LIBATTICA_INCLUDE_DIR Path needed for finding Attica include files
#
# The minimum required version of LibAttica can be specified using the
# standard syntax, e.g. find_package(LibAttica 0.20)

# Copyright (c) 2009 Frederik Gladhorn <[email protected]>
#
# Redistribution and use is allowed according to the terms of the BSD license.

# Support LIBATTICA_MIN_VERSION for compatibility:
IF(NOT LibAttica_FIND_VERSION)
SET(LibAttica_FIND_VERSION "${LIBATTICA_MIN_VERSION}")
ENDIF(NOT LibAttica_FIND_VERSION)

# the minimum version of LibAttica we require
IF(NOT LibAttica_FIND_VERSION)
SET(LibAttica_FIND_VERSION "0.1.0")
ENDIF(NOT LibAttica_FIND_VERSION)


IF (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(PC_LIBATTICA QUIET libattica)
SET(LIBATTICA_DEFINITIONS ${PC_ATTICA_CFLAGS_OTHER})
ENDIF (NOT WIN32)

FIND_PATH(LIBATTICA_INCLUDE_DIR attica/provider.h
HINTS
${PC_LIBATTICA_INCLUDEDIR}
${PC_LIBATTICA_INCLUDE_DIRS}
PATH_SUFFIXES attica
)

# Store the version number in the cache, so we don't have to search everytime:
IF(LIBATTICA_INCLUDE_DIR AND NOT LIBATTICA_VERSION)
FILE(READ ${LIBATTICA_INCLUDE_DIR}/attica/version.h LIBATTICA_VERSION_CONTENT)
STRING (REGEX MATCH "LIBATTICA_VERSION_STRING \".*\"\n" LIBATTICA_VERSION_MATCH "${LIBATTICA_VERSION_CONTENT}")
IF(LIBATTICA_VERSION_MATCH)
STRING(REGEX REPLACE "LIBATTICA_VERSION_STRING \"(.*)\"\n" "\\1" _LIBATTICA_VERSION ${LIBATTICA_VERSION_MATCH})
ENDIF(LIBATTICA_VERSION_MATCH)
SET(LIBATTICA_VERSION "${_LIBATTICA_VERSION}" CACHE STRING "Version number of LibAttica" FORCE)
ENDIF(LIBATTICA_INCLUDE_DIR AND NOT LIBATTICA_VERSION)


FIND_LIBRARY(LIBATTICA_LIBRARIES NAMES attica libattica
HINTS
${PC_LIBATTICA_LIBDIR}
${PC_LIBATTICA_LIBRARY_DIRS}
)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibAttica REQUIRED_VARS LIBATTICA_LIBRARIES LIBATTICA_INCLUDE_DIR
VERSION_VAR LIBATTICA_VERSION)

MARK_AS_ADVANCED(LIBATTICA_INCLUDE_DIR LIBATTICA_LIBRARIES)
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#cmakedefine WITH_CSYNC 1

#cmakedefine THEME_CLASS @THEME_CLASS@
#cmakedefine ENABLE_SOCKETAPI
#endif
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ set(mirall_HEADERS
mirall/proxydialog.h
)

set(mirall_LINK_LIBRARIES "")

if(ENABLE_SOCKETAPI)
list(APPEND mirall_SRCS mirall/socketapi/socketapi.cpp)
list(APPEND mirall_HEADERS mirall/socketapi/socketapi.h)
list(APPEND mirall_LINK_LIBRARIES ${LIBATTICA_LIBRARIES})
include_directories(${LIBATTICA_INCLUDE_DIR})
endif()



if( UNIX AND NOT APPLE)
if(NOT DEFINED USE_INOTIFY)
set(USE_INOTIFY ON)
Expand Down Expand Up @@ -183,6 +194,9 @@ if(NOT BUILD_OWNCLOUD_OSX_BUNDLE)
target_link_libraries(mirall ${QT_LIBRARIES} )
target_link_libraries(mirall mirallsync)
target_link_libraries(mirall ${CSYNC_LIBRARY})
if(mirall_LINK_LIBRARIES)
target_link_libraries(mirall ${mirall_LINK_LIBRARIES})
endif()

set_target_properties( mirall PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIRECTORY} )
Expand Down Expand Up @@ -220,6 +234,9 @@ set_target_properties( ${APPLICATION_EXECUTABLE} PROPERTIES
target_link_libraries( ${APPLICATION_EXECUTABLE} ${QT_LIBRARIES} )
target_link_libraries( ${APPLICATION_EXECUTABLE} owncloudsync )
target_link_libraries( ${APPLICATION_EXECUTABLE} ${CSYNC_LIBRARY} )
if(mirall_LINK_LIBRARIES)
target_link_libraries( ${APPLICATION_EXECUTABLE} ${mirall_LINK_LIBRARIES})
endif()

install(TARGETS ${APPLICATION_EXECUTABLE}
RUNTIME DESTINATION bin
Expand Down
13 changes: 12 additions & 1 deletion src/mirall/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#define LOG_TO_CALLBACK // FIXME: This should be in csync.
#include <iostream>

#include "config.h"

#include "mirall/application.h"
#include "mirall/folder.h"
#include "mirall/folderwatcher.h"
Expand All @@ -36,6 +38,7 @@
#include "mirall/csyncfolder.h"
#endif
#include "mirall/inotify.h"
#include "mirall/socketapi/socketapi.h"

#include <csync.h>

Expand Down Expand Up @@ -78,7 +81,8 @@ Application::Application(int &argc, char **argv) :
_showLogWindow(false),
_logFlush(false),
_helpOnly(false),
_logBrowser(0)
_logBrowser(0),
_socketApi(0)
{
setApplicationName( _theme->appName() );
setWindowIcon( _theme->applicationIcon() );
Expand Down Expand Up @@ -168,11 +172,18 @@ Application::Application(int &argc, char **argv) :
this,SLOT(slotSSLFailed(QNetworkReply*, QList<QSslError>)));

qDebug() << "Network Location: " << NetworkLocation::currentLocation().encoded();

#ifdef ENABLE_SOCKETAPI
_socketApi = new SocketApi(this, cfg.configPathWithAppName().append(QLatin1String("socket")), _folderMan);
#endif
}

Application::~Application()
{
delete _tray; // needed, see ctor
#ifdef ENABLE_SOCKETAPI
delete _socketApi;
#endif
qDebug() << "* Mirall shutdown";
}

Expand Down
2 changes: 2 additions & 0 deletions src/mirall/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class OwncloudSetupWizard;
class ownCloudInfo;
class SslErrorDialog;
class UpdateDetector;
class SocketApi;

class Application : public SharedTools::QtSingleApplication
{
Expand Down Expand Up @@ -124,6 +125,7 @@ protected slots:
UpdateDetector *_updateDetector;
QMap<QString, QString> _overallStatusStrings;
LogBrowser *_logBrowser;
SocketApi *_socketApi;
QString _logFile;
bool _showLogWindow;
bool _logFlush;
Expand Down
18 changes: 18 additions & 0 deletions src/mirall/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ Folder *FolderMan::folder( const QString& alias )
return 0;
}

Folder* FolderMan::folderForPath(const QUrl& path)
{
QString absolutePath = path.toLocalFile();
absolutePath.append("/");

foreach(Folder* folder, map().values())
{
if(absolutePath.startsWith(folder->path()))
{
qDebug() << "found folder: " << folder->path() << " for " << absolutePath;
return folder;
}
}

return 0;
}


SyncResult FolderMan::syncResult( const QString& alias )
{
SyncResult res;
Expand Down
6 changes: 6 additions & 0 deletions src/mirall/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "mirall/folderwatcher.h"

class QSignalMapper;
class QUrl;

namespace Mirall {

Expand Down Expand Up @@ -57,6 +58,11 @@ class FolderMan : public QObject
*/
Folder *folder( const QString& );

/**
* return the folder which the file or directory stored in path is in
*/
Folder *folderForPath( const QUrl& path );

/**
* return the last sync result by alias
*/
Expand Down
6 changes: 6 additions & 0 deletions src/mirall/mirallconfigfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ QString MirallConfigFile::configPath() const
return dir;
}

QString MirallConfigFile::configPathWithAppName() const
{
//HACK
return QFileInfo( configFile() ).dir().absolutePath().append("/");
}

QString MirallConfigFile::excludeFile() const
{
// prefer sync-exclude.lst, but if it does not exist, check for
Expand Down
1 change: 1 addition & 0 deletions src/mirall/mirallconfigfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MirallConfigFile
};

QString configPath() const;
QString configPathWithAppName() const;
QString configFile() const;
QString excludeFile() const;

Expand Down
12 changes: 8 additions & 4 deletions src/mirall/owncloudfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,16 @@ void ownCloudFolder::wipe()
SyncFileStatus ownCloudFolder::fileStatus( const QString& file )
{
if( file.isEmpty() ) return STATUS_NONE;
QFileInfo fi( path(), file );


foreach( const SyncFileItem item, _items ) {
qDebug() << "FileStatus compare: " << item.file << " <> " << fi.absoluteFilePath();
QString currentAbsoluteFilePath("%1%2");
currentAbsoluteFilePath = currentAbsoluteFilePath.arg(path()).arg(item.file);
// qDebug() << "FileStatus compare: " << currentAbsoluteFilePath << " <> " << file;


if( currentAbsoluteFilePath == file ) {

if( item.file == fi.absoluteFilePath() ) {
switch( item.instruction ) {
case CSYNC_INSTRUCTION_NONE:
return STATUS_NONE;
Expand All @@ -347,7 +351,7 @@ SyncFileStatus ownCloudFolder::fileStatus( const QString& file )
return STATUS_RENAME;
break;
case CSYNC_INSTRUCTION_NEW:
return STATUS_NEW;
return STATUS_NONE;
break;
case CSYNC_INSTRUCTION_CONFLICT:
return STATUS_CONFLICT;
Expand Down
Loading