Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Start implementing delete/recycle/rename for Glib/Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
poppeman committed Oct 14, 2016
1 parent ce96a58 commit 0555678
Show file tree
Hide file tree
Showing 21 changed files with 409 additions and 189 deletions.
122 changes: 122 additions & 0 deletions cmake/Modules/FindGLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# - Try to find Glib and its components (gio, gobject etc)
# Once done, this will define
#
# GLIB_FOUND - system has Glib
# GLIB_INCLUDE_DIRS - the Glib include directories
# GLIB_LIBRARIES - link these to use Glib
#
# Optionally, the COMPONENTS keyword can be passed to find_package()
# and Glib components can be looked for. Currently, the following
# components can be used, and they define the following variables if
# found:
#
# gio: GLIB_GIO_LIBRARIES
# gobject: GLIB_GOBJECT_LIBRARIES
# gmodule: GLIB_GMODULE_LIBRARIES
# gthread: GLIB_GTHREAD_LIBRARIES
#
# Note that the respective _INCLUDE_DIR variables are not set, since
# all headers are in the same directory as GLIB_INCLUDE_DIRS.
#
# Copyright (C) 2012 Raphael Kubo da Costa <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

find_package(PkgConfig)
pkg_check_modules(PC_GLIB QUIET glib-2.0)

find_library(GLIB_LIBRARIES
NAMES glib-2.0
HINTS ${PC_GLIB_LIBDIR}
${PC_GLIB_LIBRARY_DIRS}
)

# Files in glib's main include path may include glibconfig.h, which,
# for some odd reason, is normally in $LIBDIR/glib-2.0/include.
get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH)
find_path(GLIBCONFIG_INCLUDE_DIR
NAMES glibconfig.h
HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR}
${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS}
PATH_SUFFIXES glib-2.0/include
)

find_path(GLIB_INCLUDE_DIR
NAMES glib.h
HINTS ${PC_GLIB_INCLUDEDIR}
${PC_GLIB_INCLUDE_DIRS}
PATH_SUFFIXES glib-2.0
)

set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR})

# Version detection
if (EXISTS "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h")
file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS)
string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}")
string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}")
set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}")
endif ()

# Additional Glib components. We only look for libraries, as not all of them
# have corresponding headers and all headers are installed alongside the main
# glib ones.
foreach (_component ${GLIB_FIND_COMPONENTS})
if (${_component} STREQUAL "gio")
find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR})
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES)
elseif (${_component} STREQUAL "gobject")
find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR})
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES)
elseif (${_component} STREQUAL "gmodule")
find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR})
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES)
elseif (${_component} STREQUAL "gthread")
find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR})
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES)
elseif (${_component} STREQUAL "gio-unix")
# gio-unix is compiled as part of the gio library, but the include paths
# are separate from the shared glib ones. Since this is currently only used
# by WebKitGTK+ we don't go to extraordinary measures beyond pkg-config.
pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0)
endif ()
endforeach ()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS}
VERSION_VAR GLIB_VERSION)

mark_as_advanced(
GLIBCONFIG_INCLUDE_DIR
GLIB_GIO_LIBRARIES
GLIB_GIO_UNIX_LIBRARIES
GLIB_GMODULE_LIBRARIES
GLIB_GOBJECT_LIBRARIES
GLIB_GTHREAD_LIBRARIES
GLIB_INCLUDE_DIR
GLIB_INCLUDE_DIRS
GLIB_LIBRARIES
)
14 changes: 8 additions & 6 deletions source/LoadTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
cmake_minimum_required (VERSION 2.8)
project (LoadTest)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

include_directories(${DEPS_DIRECTORY})
link_directories(${illa_BINARY_DIR}/illa ${orz_BINARY_DIR}/orz)
FIND_PACKAGE(wxWidgets COMPONENTS core base gl net REQUIRED)

add_executable(LoadTest main.cpp)
target_link_libraries(LoadTest illa orz ${Boost_LIBRARIES})
INCLUDE_DIRECTORIES(${DEPS_DIRECTORY})
INCLUDE(${wxWidgets_USE_FILE})
LINK_DIRECTORIES(${illa_BINARY_DIR}/illa ${orz_BINARY_DIR}/orz ${wxWidgets_INCLUDE_DIRS})

ADD_EXECUTABLE(LoadTest main.cpp)
TARGET_LINK_LIBRARIES(LoadTest illa orz ${Boost_LIBRARIES})
4 changes: 4 additions & 0 deletions source/Pictus/factory_renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <GL/glew.h>
#include <wx/glcanvas.h>
#include <wx/panel.h>
#include "factory_renderer.h"

#include "w32_rendertarget.h"
#ifdef _WIN32
#include "hw3d_direct3d9_device.h"
#endif
#include "hw3d_opengl_device.h"

namespace App {
Expand Down
12 changes: 4 additions & 8 deletions source/Pictus/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,10 @@ namespace App {
if (reader == nullptr) {
return;
}
// TODO: Support on Linux
#ifdef _WIN32
auto resulting_name = dynamic_cast<IO::StreamFile*>(reader->GetStream())->Rename(new_name, GetHandle());

auto resulting_name = dynamic_cast<IO::StreamFile*>(reader->GetStream())->Rename(new_name, this);
m_cacher.RenamedImage(old_name, resulting_name);
#endif

UpdateImageInformation();
}
}
Expand All @@ -665,14 +664,11 @@ namespace App {
return;
}

// TODO: Support on Linux
#ifdef _WIN32
auto f = dynamic_cast<IO::StreamFile*>(reader->GetStream());
if (f->Delete((op == RemoveRecycle), GetHandle()))
if (f->Delete((op == RemoveRecycle), this))
{
ActiveImage(m_cacher.RemoveCurrentImage());
}
#endif

UpdateImageInformation();
}
Expand Down
7 changes: 2 additions & 5 deletions source/Pictus/w32_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,8 @@ namespace Win {
}

void Renderer::PresentFromDDSurface(Geom::RectInt destRect, std::shared_ptr<Hw3D::Texture> source, Geom::PointInt sourceTopLeft) {
//SizeFloat ppAdj{ -0.5f, -0.5f };
SizeFloat ppAdj{ 0.0f, 0.0f };
//SizeFloat ppAdj{ +0.5f, +0.5f };

//SizeFloat ppAdj{ -50.0f, -123.0f };
SizeFloat ppAdj{ -0.5f, -0.5f };
//SizeFloat ppAdj{ 0.5f, 0.5f };

m_context->SetTexture(0, source);

Expand Down
1 change: 1 addition & 0 deletions source/Stresser/CacheUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "orz/fileops.h"

#include <random>
#include <windows.h>

void CacheUser::ThreadMain() {
Output("Initializing CacheUser...");
Expand Down
1 change: 1 addition & 0 deletions source/Stresser/FolderManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Helper.h"

#include <random>
#include <windows.h>

FolderManipulator::FolderManipulator(const std::string& folder, const std::string& sourceFolder):
m_folder(folder),
Expand Down
2 changes: 2 additions & 0 deletions source/Stresser/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "orz/folder.h"
#include "orz/types.h"

#include <windows.h>

void copyFiles( const std::string& source, const std::string dest ) {
IO::Folder f;
f.Path(source.c_str());
Expand Down
1 change: 1 addition & 0 deletions source/Stresser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Logger.h"
#include "ThreadRunner.h"

#include <windows.h>
#include <boost/locale.hpp>

ThreadRunner::Ptr g_runner;
Expand Down
77 changes: 63 additions & 14 deletions source/deps/orz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,67 @@
cmake_minimum_required (VERSION 2.8)
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)

FILE(GLOB ALL_HEADER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/intl_language.h)
FILE(GLOB ALL_CPP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
FIND_PACKAGE(wxWidgets COMPONENTS core base gl net REQUIRED)

SET(
ORZ_SRC
bitconvert.cpp bitconvert.h
ByteOrder.cpp ByteOrder.h
exception.cpp exception.h
fileops.cpp fileops.h
file_cache.cpp file_cache.h
file_reader.cpp file_reader.h
file_writer.cpp file_writer.h
folder.cpp folder.h
folder_monitor.cpp folder_monitor.h
folder_monitor_imp.cpp folder_monitor_imp.h
folder_types.cpp folder_types.h
intl.cpp intl.h
intl_language.h
logger.cpp logger.h
matrix.cpp matrix.h
orz_math.cpp orz_math.h
stopwatch.cpp stopwatch.h
stream.cpp stream.h
streamconv.cpp streamconv.h
stream_file.cpp stream_file.h
stream_mem.cpp stream_mem.h
sysinfo.h
threadpool.cpp threadpool.h
types.cpp types.h
)

SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/intl_language.h PROPERTIES GENERATED 1)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/intl.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/intl_language.h)

if(WIN32)
list(APPEND ALL_CPP_SRCS Win32/sysinfo_win.cpp)
else()
list(APPEND ALL_CPP_SRCS Linux/sysinfo_linux.cpp Linux/linux_folder_monitor.cpp)
endif()
IF(WIN32)
LIST(
APPEND ORZ_SRC
Win32/sysinfo_win.cpp
Win32/fileops_win.cpp
)
SET(
PlatformLibraries
shlwapi
)
ELSE()
FIND_PACKAGE(GLIB COMPONENTS gio gobject REQUIRED)
LIST(
APPEND ORZ_SRC
Linux/sysinfo_linux.cpp
Linux/linux_folder_monitor.cpp
Linux/fileops_linux.cpp
)
SET(
PlatformIncludes
${GLIB_INCLUDE_DIRS}
)
SET(
PlatformLibraries
${GLIB_LIBRARIES}
${GLIB_GIO_LIBRARIES}
${GLIB_GOBJECT_LIBRARIES}
)
ENDIF()

ADD_CUSTOM_COMMAND(
OUTPUT
Expand All @@ -22,9 +73,7 @@ ADD_CUSTOM_COMMAND(
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../Pictus/lang_convert.py
)

add_library(orz STATIC ${ALL_CPP_SRCS} ${ALL_HEADER_SRCS} Linux/linux_folder_monitor.h)
set(libraries ${Boost_LIBRARIES})
if(WIN32)
list(APPEND libraries shlwapi)
endif()
target_link_libraries(orz ${libraries})
INCLUDE(${wxWidgets_USE_FILE})
INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIRS} ${PlatformIncludes})
ADD_LIBRARY(orz STATIC ${ORZ_SRC})
TARGET_LINK_LIBRARIES(orz ${wxWidgets_LIBRARIES} ${Boost_LIBRARIES} ${PlatformLibraries})
45 changes: 45 additions & 0 deletions source/deps/orz/Linux/fileops_linux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "../fileops.h"
#include "../file_reader.h"

#include <boost/filesystem.hpp>
#include <mutex>
#include <gio/gio.h>
#include <wx/msgdlg.h>

namespace IO {
using std::mutex;

mutex g_mutexSHFileOperation;

bool FileDelete(const std::string& file, wxWindow* hwnd) {
//return performDeleteRecycle(file, false, hwnd);
return false;
}

bool FileRecycle(const std::string& file, wxWindow* parent) {
auto gf = g_file_new_for_path(file.c_str());
GError* err = nullptr;
auto ok = g_file_trash(gf, nullptr, &err);
if(!ok)
{
wxMessageBox(wxString::FromUTF8(err->message), L"Recycle Error", wxOK);
}
g_error_free(err);
g_object_unref(gf);
return ok;
}

std::string Rename(const std::string& old_name, const std::string& new_name, wxWindow* hwnd)
{
return "";
}

bool SupportRecycle() {
return true;
}

std::string GetPath(const std::string& s)
{
return boost::filesystem::path(s).make_preferred().parent_path().string() + "/";
}
}
5 changes: 5 additions & 0 deletions source/deps/orz/Linux/sysinfo_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ namespace Sys {
}
return std::string(dest, written);
}

std::string InvalidFilenameCharacters()
{
return "/";
}
}
}
Loading

0 comments on commit 0555678

Please sign in to comment.