Skip to content

Commit

Permalink
macOS: Emoji support WiP #5661
Browse files Browse the repository at this point in the history
  • Loading branch information
guruz committed Apr 19, 2017
1 parent 5e18d5c commit 8eef2b7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 19 deletions.
13 changes: 0 additions & 13 deletions csync/src/csync.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,19 +627,6 @@ const char *csync_get_status_string(CSYNC *ctx)
return csync_vio_get_status_string(ctx);
}

#ifdef WITH_ICONV
int csync_set_iconv_codec(const char *from)
{
c_close_iconv();

if (from != NULL) {
c_setup_iconv(from);
}

return 0;
}
#endif

void csync_request_abort(CSYNC *ctx)
{
if (ctx != NULL) {
Expand Down
4 changes: 4 additions & 0 deletions csync/src/csync.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ typedef void (*csync_vio_closedir_hook) (csync_vio_handle_t *dhhandle,
typedef int (*csync_vio_stat_hook) (csync_vio_handle_t *dhhandle,
void *userdata);

typedef char* (*utf8_from_locale_hook)(const mbchar_t *wstr);



/* Compute the checksum of the given \a checksumTypeId for \a path. */
typedef const char* (*csync_checksum_hook) (
const char *path, uint32_t checksumTypeId, void *userdata);
Expand Down
8 changes: 8 additions & 0 deletions csync/src/csync_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ struct csync_s {
csync_vio_closedir_hook remote_closedir_hook;
void *vio_userdata;

// Maybe the better option?
// csync_vio_opendir_hook local_opendir_hook;
// csync_vio_readdir_hook local_readdir_hook;
// csync_vio_closedir_hook local_closedir_hook;

utf8_from_locale_hook qt_utf8_from_locale;


/* hook for comparing checksums of files during discovery */
csync_checksum_hook checksum_hook;
void *checksum_userdata;
Expand Down
2 changes: 1 addition & 1 deletion csync/src/vio/csync_vio.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ csync_vio_file_stat_t *csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle
return ctx->callbacks.remote_readdir_hook(dhandle, ctx->callbacks.vio_userdata);
break;
case LOCAL_REPLICA:
return csync_vio_local_readdir(dhandle);
return csync_vio_local_readdir(ctx, dhandle);
break;
default:
CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->replica);
Expand Down
2 changes: 1 addition & 1 deletion csync/src/vio/csync_vio_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

csync_vio_handle_t OCSYNC_EXPORT *csync_vio_local_opendir(const char *name);
int OCSYNC_EXPORT csync_vio_local_closedir(csync_vio_handle_t *dhandle);
csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_local_readdir(csync_vio_handle_t *dhandle);
csync_vio_file_stat_t OCSYNC_EXPORT *csync_vio_local_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle);

int OCSYNC_EXPORT csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf);

Expand Down
14 changes: 11 additions & 3 deletions csync/src/vio/csync_vio_local_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ int csync_vio_local_closedir(csync_vio_handle_t *dhandle) {
return rc;
}

csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) {

csync_vio_file_stat_t *csync_vio_local_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle) {

dhandle_t *handle = NULL;
csync_vio_file_stat_t *file_stat = NULL;
Expand All @@ -103,7 +104,7 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) {
if (dirent == NULL) {
goto err;
}
file_stat->name = c_utf8_from_locale(dirent->d_name);
file_stat->name = ctx->callbacks.qt_utf8_from_locale(dirent->d_name);
if (file_stat->name == NULL) {
//file_stat->original_name = c_strdup(dirent->d_name);
if (asprintf(&file_stat->original_name, "%s/%s", handle->path, dirent->d_name) < 0) {
Expand Down Expand Up @@ -149,8 +150,15 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) {

int csync_vio_local_stat(const char *uri, csync_vio_file_stat_t *buf) {
csync_stat_t sb;

#ifdef __APPLE__
// macOS accepts both normalization forms as input for the stat syscall
// (ok for WiP, for final we should not do this but have a qt_locale_from_utf8)
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Local stat %s", uri);
mbchar_t *wuri = strdup(uri);
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Xocal stat %s", wuri);
#else
mbchar_t *wuri = c_utf8_path_to_locale( uri );
#endif

if( _tstat(wuri, &sb) < 0) {
c_free_locale_string(wuri);
Expand Down
17 changes: 16 additions & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) {
}
// Special handling CSYNC_STATUS_INVALID_CHARACTERS
if (err == CSYNC_STATUS_INVALID_CHARACTERS) {
errStr = tr("Invalid characters, please rename \"%1\"").arg(errMsg);
errStr = tr("Invalid characters, please rename \"%1\"").arg(errMsg));

This comment has been minimized.

Copy link
@ckamm

ckamm Apr 21, 2017

Contributor

Stray )

}

// if there is csyncs url modifier in the error message, replace it.
Expand All @@ -697,6 +697,18 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) {
finalize(false);
}

// Instead of using the buggy iconv version c_utf8_from_locale from ocsync
char* qt_utf8_from_locale(const mbchar_t *wstr)
{
QByteArray tmp = QString::fromUtf8(wstr).normalized(QString::NormalizationForm_C).toLocal8Bit();

This comment has been minimized.

Copy link
@ogoffart

ogoffart Apr 20, 2017

Contributor

wrong order. You need to convert from locale to utf8

This comment has been minimized.

Copy link
@ogoffart

ogoffart Apr 22, 2017

Contributor

@ckamm is right, this can't work (compile) on Windows because wstr would be a wchar_t

char *ret = tmp.data();
if (ret) {

This comment has been minimized.

Copy link
@ogoffart

ogoffart Apr 20, 2017

Contributor

can never be null.

The code could simply be

return strdup(QString::fromLocale8Bit(wstr).normalized(QString::NormalizationForm_C).toUtf8().constData());

ret = strdup(ret);
}
return ret;
}


void SyncEngine::startSync()
{
if (_journal->exists()) {
Expand Down Expand Up @@ -805,6 +817,9 @@ void SyncEngine::startSync()
_csync_ctx->callbacks.checksum_hook = &CSyncChecksumHook::hook;
_csync_ctx->callbacks.checksum_userdata = &_checksum_hook;

_csync_ctx->callbacks.qt_utf8_from_locale = &qt_utf8_from_locale;

This comment has been minimized.

Copy link
@ckamm

ckamm Apr 21, 2017

Contributor

I don't haven't investigated enough to have a firm opinion here, but if only OSX is broken, I'd not change this for the other platforms. For example, the Windows c_utf8_from_locale uses WideCharToMultiByte which probably does the right thing.



_stopWatch.start();

qDebug() << "#### Discovery start #################################################### >>";
Expand Down

0 comments on commit 8eef2b7

Please sign in to comment.