summaryrefslogtreecommitdiff
path: root/src/user_share-common.c
diff options
context:
space:
mode:
authorSteve Zesch <[email protected]>2012-05-14 13:35:03 -0400
committerSteve Zesch <[email protected]>2012-05-14 13:35:03 -0400
commit130eaa7d69ed4803041774442ccb6a9d7ea1ec4c (patch)
treef7339140f1c496a53e1c43ae9f3742235f5ae1b9 /src/user_share-common.c
parentb42609046ef05f8d8be4b08ac50ea10a3c6dfe71 (diff)
downloadmate-user-share-130eaa7d69ed4803041774442ccb6a9d7ea1ec4c.tar.bz2
mate-user-share-130eaa7d69ed4803041774442ccb6a9d7ea1ec4c.tar.xz
Forked gnome-user-share. Work in progress.
Diffstat (limited to 'src/user_share-common.c')
-rw-r--r--src/user_share-common.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/user_share-common.c b/src/user_share-common.c
new file mode 100644
index 0000000..ae2fd2c
--- /dev/null
+++ b/src/user_share-common.c
@@ -0,0 +1,89 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+
+/*
+ * Copyright (C) 2004-2009 Red Hat, Inc.
+ *
+ * Caja 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.
+ *
+ * Caja 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Authors: Alexander Larsson <[email protected]>
+ * Bastien Nocera <[email protected]>
+ *
+ */
+
+#include "user_share-common.h"
+
+static char *
+lookup_special_dir (GUserDirectory directory,
+ const char *name,
+ gboolean create_dir)
+{
+ const char *special_dir;
+ char *dir;
+
+ special_dir = g_get_user_special_dir (directory);
+ if (special_dir != NULL && strcmp (special_dir, g_get_home_dir ()) != 0) {
+ if (create_dir != FALSE)
+ g_mkdir_with_parents (special_dir, 0755);
+ return g_strdup (special_dir);
+ }
+
+ dir = g_build_filename (g_get_home_dir (), name, NULL);
+ if (create_dir != FALSE)
+ g_mkdir_with_parents (dir, 0755);
+ return dir;
+}
+
+char *
+lookup_public_dir (void)
+{
+ return lookup_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE,
+ "Public",
+ TRUE);
+}
+
+char *
+lookup_download_dir (void)
+{
+ return lookup_special_dir (G_USER_DIRECTORY_DOWNLOAD,
+ "Downloads",
+ TRUE);
+}
+
+GFile *
+lookup_dir_with_fallback (GUserDirectory directory)
+{
+ GFile *file;
+ char *path;
+ const char *name;
+
+ if (directory == G_USER_DIRECTORY_PUBLIC_SHARE)
+ name = "Public";
+ else if (directory == G_USER_DIRECTORY_DOWNLOAD)
+ name = "Downloads";
+ else
+ g_assert_not_reached ();
+
+ path = lookup_special_dir (directory,
+ name,
+ FALSE);
+
+ if (path == NULL)
+ return NULL;
+
+ file = g_file_new_for_path (path);
+ g_free (path);
+
+ return file;
+}