+ return f.getName().length() == 0 ? ROOT_PATH : f.getName();
+ }
+
+ /**
+ * Sets the name of the file
+ *
+ * Does nothing if the new name is null, empty or includes "/" ; or if the file is the root directory
+ */
+ public void setFileName(String name) {
+ Log_OC.d(TAG, "OCFile name changin from " + mRemotePath);
+ if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(ROOT_PATH)) {
+ String parent = (new File(getRemotePath())).getParent();
+ parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR;
+ mRemotePath = parent + name;
+ if (isFolder()) {
+ mRemotePath += PATH_SEPARATOR;
+ }
+ Log_OC.d(TAG, "OCFile name changed to " + mRemotePath);
+
+ // Notify MediaScanner about removed file
+ Intent intent1 = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ intent1.setData(Uri.fromFile(new File(this.getStoragePath())));
+ MainApp.getAppContext().sendBroadcast(intent1);
+
+ // Notify MediaScanner about new file
+ Intent intent2 = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
+ String folder = new File(this.getStoragePath()).getParent();
+ intent2.setData(Uri.fromFile(new File(folder+ PATH_SEPARATOR+name)));
+ MainApp.getAppContext().sendBroadcast(intent2);
+ }