Cleanup: Move fsmenu.c to C++
See #103343 Co-authored-by: Ray Molenkamp <github@lazydodo.com> Pull Request: https://projects.blender.org/blender/blender/pulls/110797
This commit is contained in:
@@ -35,8 +35,8 @@ set(SRC
|
||||
filelist.cc
|
||||
filesel.cc
|
||||
folder_history.cc
|
||||
fsmenu.c
|
||||
fsmenu_system.c
|
||||
fsmenu.cc
|
||||
fsmenu_system.cc
|
||||
space_file.cc
|
||||
|
||||
file_indexer.hh
|
||||
|
||||
@@ -32,27 +32,27 @@
|
||||
|
||||
/* FSMENU HANDLING */
|
||||
|
||||
typedef struct FSMenu {
|
||||
struct FSMenu {
|
||||
FSMenuEntry *fsmenu_system;
|
||||
FSMenuEntry *fsmenu_system_bookmarks;
|
||||
FSMenuEntry *fsmenu_bookmarks;
|
||||
FSMenuEntry *fsmenu_recent;
|
||||
FSMenuEntry *fsmenu_other;
|
||||
} FSMenu;
|
||||
};
|
||||
|
||||
static FSMenu *g_fsmenu = NULL;
|
||||
static FSMenu *g_fsmenu = nullptr;
|
||||
|
||||
FSMenu *ED_fsmenu_get(void)
|
||||
{
|
||||
if (!g_fsmenu) {
|
||||
g_fsmenu = MEM_callocN(sizeof(FSMenu), "fsmenu");
|
||||
g_fsmenu = MEM_cnew<FSMenu>(__func__);
|
||||
}
|
||||
return g_fsmenu;
|
||||
}
|
||||
|
||||
FSMenuEntry *ED_fsmenu_get_category(FSMenu *fsmenu, FSMenuCategory category)
|
||||
{
|
||||
FSMenuEntry *fsm_head = NULL;
|
||||
FSMenuEntry *fsm_head = nullptr;
|
||||
|
||||
switch (category) {
|
||||
case FS_CATEGORY_SYSTEM:
|
||||
@@ -132,11 +132,11 @@ void ED_fsmenu_entry_set_path(FSMenuEntry *fsentry, const char *path)
|
||||
|
||||
MEM_SAFE_FREE(fsentry->path);
|
||||
|
||||
fsentry->path = (path && path[0]) ? BLI_strdup(path) : NULL;
|
||||
fsentry->path = (path && path[0]) ? BLI_strdup(path) : nullptr;
|
||||
|
||||
BLI_path_join(tmp_name,
|
||||
sizeof(tmp_name),
|
||||
BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL),
|
||||
BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, nullptr),
|
||||
BLENDER_BOOKMARK_FILE);
|
||||
fsmenu_write_file(ED_fsmenu_get(), tmp_name);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ char *ED_fsmenu_entry_get_name(FSMenuEntry *fsentry)
|
||||
return fsentry->name;
|
||||
}
|
||||
|
||||
/* Here we abuse fsm_iter->name, keeping first char NULL. */
|
||||
/* Here we abuse fsm_iter->name, keeping first char nullptr. */
|
||||
char *name = fsentry->name + 1;
|
||||
size_t name_size = sizeof(fsentry->name) - 1;
|
||||
|
||||
@@ -200,7 +200,7 @@ void ED_fsmenu_entry_set_name(FSMenuEntry *fsentry, const char *name)
|
||||
|
||||
BLI_path_join(tmp_name,
|
||||
sizeof(tmp_name),
|
||||
BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL),
|
||||
BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, nullptr),
|
||||
BLENDER_BOOKMARK_FILE);
|
||||
fsmenu_write_file(ED_fsmenu_get(), tmp_name);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ void fsmenu_entry_refresh_valid(FSMenuEntry *fsentry)
|
||||
/* XXX Special case, always consider those as valid.
|
||||
* Thanks to Windows, which can spend five seconds to perform a mere stat() call on those paths
|
||||
* See #43684. */
|
||||
const char *exceptions[] = {"A:\\", "B:\\", NULL};
|
||||
const char *exceptions[] = {"A:\\", "B:\\", nullptr};
|
||||
const size_t exceptions_len[] = {strlen(exceptions[0]), strlen(exceptions[1]), 0};
|
||||
int i;
|
||||
|
||||
@@ -292,7 +292,7 @@ void fsmenu_insert_entry(FSMenu *fsmenu,
|
||||
}
|
||||
}
|
||||
|
||||
fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme");
|
||||
fsm_iter = static_cast<FSMenuEntry *>(MEM_mallocN(sizeof(*fsm_iter), "fsme"));
|
||||
if (has_trailing_slash) {
|
||||
fsm_iter->path = BLI_strdup(path);
|
||||
}
|
||||
@@ -369,7 +369,7 @@ void fsmenu_insert_entry(FSMenu *fsmenu,
|
||||
|
||||
void fsmenu_remove_entry(FSMenu *fsmenu, FSMenuCategory category, int idx)
|
||||
{
|
||||
FSMenuEntry *fsm_prev = NULL;
|
||||
FSMenuEntry *fsm_prev = nullptr;
|
||||
FSMenuEntry *fsm_iter;
|
||||
FSMenuEntry *fsm_head;
|
||||
|
||||
@@ -382,7 +382,7 @@ void fsmenu_remove_entry(FSMenu *fsmenu, FSMenuCategory category, int idx)
|
||||
if (fsm_iter) {
|
||||
/* you should only be able to remove entries that were
|
||||
* not added by default, like windows drives.
|
||||
* also separators (where path == NULL) shouldn't be removed */
|
||||
* also separators (where path == nullptr) shouldn't be removed */
|
||||
if (fsm_iter->save && fsm_iter->path) {
|
||||
|
||||
/* remove fsme from list */
|
||||
@@ -402,7 +402,7 @@ void fsmenu_remove_entry(FSMenu *fsmenu, FSMenuCategory category, int idx)
|
||||
|
||||
bool fsmenu_write_file(FSMenu *fsmenu, const char *filepath)
|
||||
{
|
||||
FSMenuEntry *fsm_iter = NULL;
|
||||
FSMenuEntry *fsm_iter = nullptr;
|
||||
char fsm_name[FILE_MAX];
|
||||
int nwritten = 0;
|
||||
|
||||
@@ -456,7 +456,7 @@ void fsmenu_read_bookmarks(FSMenu *fsmenu, const char *filepath)
|
||||
|
||||
name[0] = '\0';
|
||||
|
||||
while (fgets(line, sizeof(line), fp) != NULL) { /* read a line */
|
||||
while (fgets(line, sizeof(line), fp) != nullptr) { /* read a line */
|
||||
if (STRPREFIX(line, "[Bookmarks]")) {
|
||||
category = FS_CATEGORY_BOOKMARKS;
|
||||
}
|
||||
@@ -514,10 +514,10 @@ static void fsmenu_free_category(FSMenu *fsmenu, FSMenuCategory category)
|
||||
void fsmenu_refresh_system_category(FSMenu *fsmenu)
|
||||
{
|
||||
fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM);
|
||||
ED_fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM, NULL);
|
||||
ED_fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM, nullptr);
|
||||
|
||||
fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS);
|
||||
ED_fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, NULL);
|
||||
ED_fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, nullptr);
|
||||
|
||||
/* Add all entries to system category */
|
||||
fsmenu_read_system(fsmenu, true);
|
||||
@@ -525,7 +525,7 @@ void fsmenu_refresh_system_category(FSMenu *fsmenu)
|
||||
|
||||
static void fsmenu_free_ex(FSMenu **fsmenu)
|
||||
{
|
||||
if (*fsmenu != NULL) {
|
||||
if (*fsmenu != nullptr) {
|
||||
fsmenu_free_category(*fsmenu, FS_CATEGORY_SYSTEM);
|
||||
fsmenu_free_category(*fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS);
|
||||
fsmenu_free_category(*fsmenu, FS_CATEGORY_BOOKMARKS);
|
||||
@@ -534,7 +534,7 @@ static void fsmenu_free_ex(FSMenu **fsmenu)
|
||||
MEM_freeN(*fsmenu);
|
||||
}
|
||||
|
||||
*fsmenu = NULL;
|
||||
*fsmenu = nullptr;
|
||||
}
|
||||
|
||||
void fsmenu_free(void)
|
||||
@@ -546,16 +546,16 @@ static void fsmenu_copy_category(FSMenu *fsmenu_dst,
|
||||
FSMenu *fsmenu_src,
|
||||
const FSMenuCategory category)
|
||||
{
|
||||
FSMenuEntry *fsm_dst_prev = NULL, *fsm_dst_head = NULL;
|
||||
FSMenuEntry *fsm_dst_prev = nullptr, *fsm_dst_head = nullptr;
|
||||
FSMenuEntry *fsm_src_iter = ED_fsmenu_get_category(fsmenu_src, category);
|
||||
|
||||
for (; fsm_src_iter != NULL; fsm_src_iter = fsm_src_iter->next) {
|
||||
FSMenuEntry *fsm_dst = MEM_dupallocN(fsm_src_iter);
|
||||
if (fsm_dst->path != NULL) {
|
||||
fsm_dst->path = MEM_dupallocN(fsm_dst->path);
|
||||
for (; fsm_src_iter != nullptr; fsm_src_iter = fsm_src_iter->next) {
|
||||
FSMenuEntry *fsm_dst = static_cast<FSMenuEntry *>(MEM_dupallocN(fsm_src_iter));
|
||||
if (fsm_dst->path != nullptr) {
|
||||
fsm_dst->path = static_cast<char *>(MEM_dupallocN(fsm_dst->path));
|
||||
}
|
||||
|
||||
if (fsm_dst_prev != NULL) {
|
||||
if (fsm_dst_prev != nullptr) {
|
||||
fsm_dst_prev->next = fsm_dst;
|
||||
}
|
||||
else {
|
||||
@@ -569,7 +569,7 @@ static void fsmenu_copy_category(FSMenu *fsmenu_dst,
|
||||
|
||||
static FSMenu *fsmenu_copy(FSMenu *fsmenu)
|
||||
{
|
||||
FSMenu *fsmenu_copy = MEM_dupallocN(fsmenu);
|
||||
FSMenu *fsmenu_copy = static_cast<FSMenu *>(MEM_dupallocN(fsmenu));
|
||||
|
||||
fsmenu_copy_category(fsmenu_copy, fsmenu_copy, FS_CATEGORY_SYSTEM);
|
||||
fsmenu_copy_category(fsmenu_copy, fsmenu_copy, FS_CATEGORY_SYSTEM_BOOKMARKS);
|
||||
@@ -604,15 +604,15 @@ static void fsmenu_bookmark_validate_job_startjob(
|
||||
* NOLINTNEXTLINE: readability-non-const-parameter. */
|
||||
bool *stop,
|
||||
bool *do_update,
|
||||
float *UNUSED(progress))
|
||||
float * /*progress*/)
|
||||
{
|
||||
FSMenu *fsmenu = fsmenuv;
|
||||
FSMenu *fsmenu = static_cast<FSMenu *>(fsmenuv);
|
||||
|
||||
int categories[] = {
|
||||
FS_CATEGORY_SYSTEM, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_CATEGORY_BOOKMARKS, FS_CATEGORY_RECENT};
|
||||
|
||||
for (size_t i = ARRAY_SIZE(categories); i--;) {
|
||||
FSMenuEntry *fsm_iter = ED_fsmenu_get_category(fsmenu, categories[i]);
|
||||
FSMenuEntry *fsm_iter = ED_fsmenu_get_category(fsmenu, FSMenuCategory(categories[i]));
|
||||
for (; fsm_iter; fsm_iter = fsm_iter->next) {
|
||||
if (*stop) {
|
||||
return;
|
||||
@@ -627,19 +627,20 @@ static void fsmenu_bookmark_validate_job_startjob(
|
||||
|
||||
static void fsmenu_bookmark_validate_job_update(void *fsmenuv)
|
||||
{
|
||||
FSMenu *fsmenu_job = fsmenuv;
|
||||
FSMenu *fsmenu_job = static_cast<FSMenu *>(fsmenuv);
|
||||
|
||||
int categories[] = {
|
||||
FS_CATEGORY_SYSTEM, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_CATEGORY_BOOKMARKS, FS_CATEGORY_RECENT};
|
||||
|
||||
for (size_t i = ARRAY_SIZE(categories); i--;) {
|
||||
FSMenuEntry *fsm_iter_src = ED_fsmenu_get_category(fsmenu_job, categories[i]);
|
||||
FSMenuEntry *fsm_iter_dst = ED_fsmenu_get_category(ED_fsmenu_get(), categories[i]);
|
||||
for (; fsm_iter_dst != NULL; fsm_iter_dst = fsm_iter_dst->next) {
|
||||
while (fsm_iter_src != NULL && !STREQ(fsm_iter_dst->path, fsm_iter_src->path)) {
|
||||
FSMenuEntry *fsm_iter_src = ED_fsmenu_get_category(fsmenu_job, FSMenuCategory(categories[i]));
|
||||
FSMenuEntry *fsm_iter_dst = ED_fsmenu_get_category(ED_fsmenu_get(),
|
||||
FSMenuCategory(categories[i]));
|
||||
for (; fsm_iter_dst != nullptr; fsm_iter_dst = fsm_iter_dst->next) {
|
||||
while (fsm_iter_src != nullptr && !STREQ(fsm_iter_dst->path, fsm_iter_src->path)) {
|
||||
fsm_iter_src = fsm_iter_src->next;
|
||||
}
|
||||
if (fsm_iter_src == NULL) {
|
||||
if (fsm_iter_src == nullptr) {
|
||||
return;
|
||||
}
|
||||
fsm_iter_dst->valid = fsm_iter_src->valid;
|
||||
@@ -655,7 +656,7 @@ static void fsmenu_bookmark_validate_job_end(void *fsmenuv)
|
||||
|
||||
static void fsmenu_bookmark_validate_job_free(void *fsmenuv)
|
||||
{
|
||||
FSMenu *fsmenu = fsmenuv;
|
||||
FSMenu *fsmenu = static_cast<FSMenu *>(fsmenuv);
|
||||
fsmenu_free_ex(&fsmenu);
|
||||
}
|
||||
|
||||
@@ -665,13 +666,17 @@ static void fsmenu_bookmark_validate_job_start(wmWindowManager *wm)
|
||||
FSMenu *fsmenu_job = fsmenu_copy(g_fsmenu);
|
||||
|
||||
/* setup job */
|
||||
wm_job = WM_jobs_get(
|
||||
wm, wm->winactive, wm, "Validating Bookmarks...", 0, WM_JOB_TYPE_FSMENU_BOOKMARK_VALIDATE);
|
||||
wm_job = WM_jobs_get(wm,
|
||||
wm->winactive,
|
||||
wm,
|
||||
"Validating Bookmarks...",
|
||||
eWM_JobFlag(0),
|
||||
WM_JOB_TYPE_FSMENU_BOOKMARK_VALIDATE);
|
||||
WM_jobs_customdata_set(wm_job, fsmenu_job, fsmenu_bookmark_validate_job_free);
|
||||
WM_jobs_timer(wm_job, 0.01, NC_SPACE | ND_SPACE_FILE_LIST, NC_SPACE | ND_SPACE_FILE_LIST);
|
||||
WM_jobs_callbacks(wm_job,
|
||||
fsmenu_bookmark_validate_job_startjob,
|
||||
NULL,
|
||||
nullptr,
|
||||
fsmenu_bookmark_validate_job_update,
|
||||
fsmenu_bookmark_validate_job_end);
|
||||
|
||||
@@ -74,7 +74,7 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
|
||||
{
|
||||
char filepath[FILE_MAX];
|
||||
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home != NULL) {
|
||||
if (xdg_config_home != nullptr) {
|
||||
BLI_path_join(filepath, sizeof(filepath), xdg_config_home, "user-dirs.dirs");
|
||||
}
|
||||
else {
|
||||
@@ -82,17 +82,17 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
|
||||
}
|
||||
fp = BLI_fopen(filepath, "r");
|
||||
if (!fp) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
/* By default there are 8 paths. */
|
||||
GHash *xdg_map = BLI_ghash_str_new_ex(__func__, 8);
|
||||
while (fgets(l, sizeof(l), fp) != NULL) { /* read a line */
|
||||
while (fgets(l, sizeof(l), fp) != nullptr) { /* read a line */
|
||||
|
||||
/* Avoid inserting invalid values. */
|
||||
if (STRPREFIX(l, "XDG_")) {
|
||||
char *l_value = strchr(l, '=');
|
||||
if (l_value != NULL) {
|
||||
if (l_value != nullptr) {
|
||||
*l_value = '\0';
|
||||
l_value++;
|
||||
|
||||
@@ -125,7 +125,7 @@ static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
|
||||
|
||||
static void fsmenu_xdg_user_dirs_free(GHash *xdg_map)
|
||||
{
|
||||
if (xdg_map != NULL) {
|
||||
if (xdg_map != nullptr) {
|
||||
BLI_ghash_free(xdg_map, MEM_freeN, MEM_freeN);
|
||||
}
|
||||
}
|
||||
@@ -139,15 +139,15 @@ static void fsmenu_xdg_user_dirs_free(GHash *xdg_map)
|
||||
* \param default_path: Directory name to check in $HOME, also used for the menu entry name.
|
||||
*/
|
||||
static void fsmenu_xdg_insert_entry(GHash *xdg_map,
|
||||
struct FSMenu *fsmenu,
|
||||
FSMenu *fsmenu,
|
||||
const char *key,
|
||||
const char *default_path,
|
||||
int icon,
|
||||
const char *home)
|
||||
{
|
||||
char xdg_path_buf[FILE_MAXDIR];
|
||||
const char *xdg_path = (const char *)(xdg_map ? BLI_ghash_lookup(xdg_map, key) : NULL);
|
||||
if (xdg_path == NULL) {
|
||||
const char *xdg_path = (const char *)(xdg_map ? BLI_ghash_lookup(xdg_map, key) : nullptr);
|
||||
if (xdg_path == nullptr) {
|
||||
BLI_path_join(xdg_path_buf, sizeof(xdg_path_buf), home, default_path);
|
||||
xdg_path = xdg_path_buf;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ static void fsmenu_xdg_insert_entry(GHash *xdg_map,
|
||||
|
||||
#ifdef WIN32
|
||||
/* Add a Windows known folder path to the System list. */
|
||||
static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
|
||||
static void fsmenu_add_windows_folder(FSMenu *fsmenu,
|
||||
FSMenuCategory category,
|
||||
REFKNOWNFOLDERID rfid,
|
||||
const char *name,
|
||||
@@ -168,7 +168,7 @@ static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
|
||||
{
|
||||
LPWSTR pPath;
|
||||
char line[FILE_MAXDIR];
|
||||
if (SHGetKnownFolderPath(rfid, 0, NULL, &pPath) == S_OK) {
|
||||
if (SHGetKnownFolderPath(rfid, 0, nullptr, &pPath) == S_OK) {
|
||||
BLI_strncpy_wchar_as_utf8(line, pPath, FILE_MAXDIR);
|
||||
CoTaskMemFree(pPath);
|
||||
fsmenu_insert_entry(fsmenu, category, line, name, icon, flag);
|
||||
@@ -176,7 +176,7 @@ static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
|
||||
}
|
||||
#endif
|
||||
|
||||
void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
|
||||
{
|
||||
char line[FILE_MAXDIR];
|
||||
#ifdef WIN32
|
||||
@@ -194,7 +194,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
tmps[1] = ':';
|
||||
tmps[2] = '\\';
|
||||
tmps[3] = '\0';
|
||||
name = NULL;
|
||||
name = nullptr;
|
||||
|
||||
/* Skip over floppy disks A & B. */
|
||||
if (i > 1) {
|
||||
@@ -203,12 +203,11 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
IShellFolder *desktop;
|
||||
if (SHGetDesktopFolder(&desktop) == S_OK) {
|
||||
PIDLIST_RELATIVE volume;
|
||||
if (desktop->lpVtbl->ParseDisplayName(
|
||||
desktop, NULL, NULL, wline, NULL, &volume, NULL) == S_OK) {
|
||||
if (desktop->ParseDisplayName(nullptr, nullptr, wline, nullptr, &volume, nullptr) ==
|
||||
S_OK) {
|
||||
STRRET volume_name;
|
||||
volume_name.uType = STRRET_WSTR;
|
||||
if (desktop->lpVtbl->GetDisplayNameOf(
|
||||
desktop, volume, SHGDN_FORADDRESSBAR, &volume_name) == S_OK) {
|
||||
if (desktop->GetDisplayNameOf(volume, SHGDN_FORADDRESSBAR, &volume_name) == S_OK) {
|
||||
wchar_t *volume_name_wchar;
|
||||
if (StrRetToStrW(&volume_name, volume, &volume_name_wchar) == S_OK) {
|
||||
BLI_strncpy_wchar_as_utf8(line, volume_name_wchar, FILE_MAXDIR);
|
||||
@@ -218,10 +217,10 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
}
|
||||
CoTaskMemFree(volume);
|
||||
}
|
||||
desktop->lpVtbl->Release(desktop);
|
||||
desktop->Release();
|
||||
}
|
||||
}
|
||||
if (name == NULL) {
|
||||
if (name == nullptr) {
|
||||
name = tmps;
|
||||
}
|
||||
|
||||
@@ -247,7 +246,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
tmps,
|
||||
name,
|
||||
icon,
|
||||
FS_INSERT_SORTED | FS_INSERT_NO_VALIDATE);
|
||||
FSMenuInsert(FS_INSERT_SORTED | FS_INSERT_NO_VALIDATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,63 +256,67 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
/* These items are shown in System List. */
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Profile,
|
||||
FOLDERID_Profile,
|
||||
N_("Home"),
|
||||
ICON_HOME,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Desktop,
|
||||
FOLDERID_Desktop,
|
||||
N_("Desktop"),
|
||||
ICON_DESKTOP,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Documents,
|
||||
FOLDERID_Documents,
|
||||
N_("Documents"),
|
||||
ICON_DOCUMENTS,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Downloads,
|
||||
FOLDERID_Downloads,
|
||||
N_("Downloads"),
|
||||
ICON_IMPORT,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Music,
|
||||
FOLDERID_Music,
|
||||
N_("Music"),
|
||||
ICON_FILE_SOUND,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Pictures,
|
||||
FOLDERID_Pictures,
|
||||
N_("Pictures"),
|
||||
ICON_FILE_IMAGE,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Videos,
|
||||
FOLDERID_Videos,
|
||||
N_("Videos"),
|
||||
ICON_FILE_MOVIE,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Fonts,
|
||||
FOLDERID_Fonts,
|
||||
N_("Fonts"),
|
||||
ICON_FILE_FONT,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_SkyDrive,
|
||||
FOLDERID_SkyDrive,
|
||||
N_("OneDrive"),
|
||||
ICON_URL,
|
||||
FS_INSERT_LAST);
|
||||
|
||||
/* These items are just put in path cache for thumbnail views and if bookmarked. */
|
||||
|
||||
fsmenu_add_windows_folder(
|
||||
fsmenu, FS_CATEGORY_OTHER, &FOLDERID_UserProfiles, NULL, ICON_COMMUNITY, FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_OTHER,
|
||||
FOLDERID_UserProfiles,
|
||||
nullptr,
|
||||
ICON_COMMUNITY,
|
||||
FS_INSERT_LAST);
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
@@ -337,7 +340,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
\
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, line, name, icon, FS_INSERT_LAST);
|
||||
|
||||
FS_MACOS_PATH("%s/", NULL, ICON_HOME)
|
||||
FS_MACOS_PATH("%s/", nullptr, ICON_HOME)
|
||||
FS_MACOS_PATH("%s/Desktop/", N_("Desktop"), ICON_DESKTOP)
|
||||
FS_MACOS_PATH("%s/Documents/", N_("Documents"), ICON_DOCUMENTS)
|
||||
FS_MACOS_PATH("%s/Downloads/", N_("Downloads"), ICON_IMPORT)
|
||||
@@ -356,15 +359,15 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
/* We get all volumes sorted including network and do not relay
|
||||
* on user-defined finder visibility, less confusing. */
|
||||
|
||||
CFURLRef cfURL = NULL;
|
||||
CFURLRef cfURL = nullptr;
|
||||
CFURLEnumeratorResult result = kCFURLEnumeratorSuccess;
|
||||
CFURLEnumeratorRef volEnum = CFURLEnumeratorCreateForMountedVolumes(
|
||||
NULL, kCFURLEnumeratorSkipInvisibles, NULL);
|
||||
nullptr, kCFURLEnumeratorSkipInvisibles, nullptr);
|
||||
|
||||
while (result != kCFURLEnumeratorEnd) {
|
||||
char defPath[FILE_MAX];
|
||||
|
||||
result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, NULL);
|
||||
result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, nullptr);
|
||||
if (result != kCFURLEnumeratorSuccess) {
|
||||
continue;
|
||||
}
|
||||
@@ -373,25 +376,26 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
|
||||
/* Get name of the volume. */
|
||||
char display_name[FILE_MAXFILE] = "";
|
||||
CFStringRef nameString = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeLocalizedNameKey, &nameString, NULL);
|
||||
if (nameString != NULL) {
|
||||
CFStringRef nameString = nullptr;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeLocalizedNameKey, &nameString, nullptr);
|
||||
if (nameString != nullptr) {
|
||||
CFStringGetCString(nameString, display_name, sizeof(display_name), kCFStringEncodingUTF8);
|
||||
CFRelease(nameString);
|
||||
}
|
||||
|
||||
/* Set icon for regular, removable or network drive. */
|
||||
int icon = ICON_DISK_DRIVE;
|
||||
CFBooleanRef localKey = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsLocalKey, &localKey, NULL);
|
||||
if (localKey != NULL) {
|
||||
CFBooleanRef localKey = nullptr;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsLocalKey, &localKey, nullptr);
|
||||
if (localKey != nullptr) {
|
||||
if (!CFBooleanGetValue(localKey)) {
|
||||
icon = ICON_NETWORK_DRIVE;
|
||||
}
|
||||
else {
|
||||
CFBooleanRef ejectableKey = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsEjectableKey, &ejectableKey, NULL);
|
||||
if (ejectableKey != NULL) {
|
||||
CFBooleanRef ejectableKey = nullptr;
|
||||
CFURLCopyResourcePropertyForKey(
|
||||
cfURL, kCFURLVolumeIsEjectableKey, &ejectableKey, nullptr);
|
||||
if (ejectableKey != nullptr) {
|
||||
if (CFBooleanGetValue(ejectableKey)) {
|
||||
icon = ICON_EXTERNAL_DRIVE;
|
||||
}
|
||||
@@ -404,7 +408,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM,
|
||||
defPath,
|
||||
display_name[0] ? display_name : NULL,
|
||||
display_name[0] ? display_name : nullptr,
|
||||
icon,
|
||||
FS_INSERT_SORTED);
|
||||
}
|
||||
@@ -419,7 +423,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
if (read_bookmarks) {
|
||||
UInt32 seed;
|
||||
LSSharedFileListRef list = LSSharedFileListCreate(
|
||||
NULL, kLSSharedFileListFavoriteItems, NULL);
|
||||
nullptr, kLSSharedFileListFavoriteItems, nullptr);
|
||||
CFArrayRef pathesArray = LSSharedFileListCopySnapshot(list, &seed);
|
||||
CFIndex pathesCount = CFArrayGetCount(pathesArray);
|
||||
|
||||
@@ -427,19 +431,19 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(
|
||||
pathesArray, i);
|
||||
|
||||
CFURLRef cfURL = NULL;
|
||||
CFURLRef cfURL = nullptr;
|
||||
OSErr err = LSSharedFileListItemResolve(itemRef,
|
||||
kLSSharedFileListNoUserInteraction |
|
||||
kLSSharedFileListDoNotMountVolumes,
|
||||
&cfURL,
|
||||
NULL);
|
||||
nullptr);
|
||||
if (err != noErr || !cfURL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CFStringRef pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
|
||||
|
||||
if (pathString == NULL ||
|
||||
if (pathString == nullptr ||
|
||||
!CFStringGetCString(pathString, line, sizeof(line), kCFStringEncodingUTF8))
|
||||
{
|
||||
continue;
|
||||
@@ -448,8 +452,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
/* Exclude "all my files" as it makes no sense in blender file-selector. */
|
||||
/* Exclude "airdrop" if wlan not active as it would show "" ) */
|
||||
if (!strstr(line, "myDocuments.cannedSearch") && (*line != '\0')) {
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_FILE_FOLDER, FS_INSERT_LAST);
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
line,
|
||||
nullptr,
|
||||
ICON_FILE_FOLDER,
|
||||
FS_INSERT_LAST);
|
||||
}
|
||||
|
||||
CFRelease(pathString);
|
||||
@@ -499,11 +507,11 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
int found = 0;
|
||||
# ifdef __linux__
|
||||
/* loop over mount points */
|
||||
struct mntent *mnt;
|
||||
mntent *mnt;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent(MOUNTED, "r");
|
||||
if (fp == NULL) {
|
||||
if (fp == nullptr) {
|
||||
fprintf(stderr, "could not get a list of mounted file-systems\n");
|
||||
}
|
||||
else {
|
||||
@@ -521,8 +529,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
continue;
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM,
|
||||
mnt->mnt_dir,
|
||||
nullptr,
|
||||
ICON_DISK_DRIVE,
|
||||
FS_INSERT_SORTED);
|
||||
|
||||
found = 1;
|
||||
}
|
||||
@@ -532,8 +544,8 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
}
|
||||
/* Check `gvfs` shares. */
|
||||
const char *const xdg_runtime_dir = BLI_getenv("XDG_RUNTIME_DIR");
|
||||
if (xdg_runtime_dir != NULL) {
|
||||
struct direntry *dirs;
|
||||
if (xdg_runtime_dir != nullptr) {
|
||||
direntry *dirs;
|
||||
char filepath[FILE_MAX];
|
||||
BLI_path_join(filepath, sizeof(filepath), xdg_runtime_dir, "gvfs/");
|
||||
/* Avoid error message if the directory doesn't exist as this isn't a requirement. */
|
||||
@@ -551,7 +563,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
/* Directory names contain a lot of unwanted text.
|
||||
* Assuming every entry ends with the share name. */
|
||||
const char *label = strstr(dirname, "share=");
|
||||
if (label != NULL) {
|
||||
if (label != nullptr) {
|
||||
/* Move pointer so `share=` is trimmed off or use full `dirname` as label. */
|
||||
const char *label_test = label + 6;
|
||||
label = *label_test ? label_test : dirname;
|
||||
@@ -569,13 +581,13 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
/* fallback */
|
||||
if (!found) {
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, "/", NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
fsmenu, FS_CATEGORY_SYSTEM, "/", nullptr, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
#if defined(__APPLE__)
|
||||
/* Quiet warnings. */
|
||||
UNUSED_VARS(fsmenu_xdg_insert_entry, fsmenu_xdg_user_dirs_parse, fsmenu_xdg_user_dirs_free);
|
||||
#endif
|
||||
@@ -587,7 +599,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
\
|
||||
if (BLI_strnlen(dir, 3) > 2) { \
|
||||
\
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, dir, NULL, icon, FS_INSERT_LAST); \
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, dir, nullptr, icon, FS_INSERT_LAST); \
|
||||
}
|
||||
|
||||
FS_UDIR_PATH(U.fontdir, ICON_FILE_FONT)
|
||||
Reference in New Issue
Block a user