Browse Source

UI: Add ability to drop html files

(Edit by Jim: Added a check to make sure that the browser source exists
due to the fact that it's technically optional)

Closes jp9000/obs-studio#905
mntone 8 years ago
parent
commit
d70c97db3a
2 changed files with 36 additions and 41 deletions
  1. 34 40
      UI/window-basic-main-dropfiles.cpp
  2. 2 1
      UI/window-basic-main.hpp

+ 34 - 40
UI/window-basic-main-dropfiles.cpp

@@ -19,6 +19,10 @@ static const char *imageExtensions[] = {
 	"bmp", "tga", "png", "jpg", "jpeg", "gif", nullptr
 };
 
+static const char *htmlExtensions[] = {
+	"htm", "html", nullptr
+};
+
 static const char *mediaExtensions[] = {
 	"3ga", "669", "a52", "aac", "ac3", "adt", "adts", "aif", "aifc",
 	"aiff", "amb", "amr", "aob", "ape", "au", "awb", "caf", "dts",
@@ -95,8 +99,17 @@ void OBSBasic::AddDropSource(const char *data, DropType image)
 		name = QUrl::fromLocalFile(QString(data)).fileName();
 		type = "ffmpeg_source";
 		break;
+	case DropType_Html:
+		obs_data_set_bool(settings, "is_local_file", true);
+		obs_data_set_string(settings, "local_file", data);
+		name = QUrl::fromLocalFile(QString(data)).fileName();
+		type = "browser_source";
+		break;
 	}
 
+	if (!obs_source_get_display_name(type))
+		return;
+
 	if (name.isEmpty())
 		name = obs_source_get_display_name(type);
 	source = obs_source_create(type,
@@ -147,46 +160,27 @@ void OBSBasic::dropEvent(QDropEvent *event)
 
 			const char **cmp;
 
-			cmp = textExtensions;
-			while (*cmp) {
-				if (strcmp(*cmp, suffix) == 0) {
-					AddDropSource(QT_TO_UTF8(file),
-							DropType_Text);
-					found = true;
-					break;
-				}
-
-				cmp++;
-			}
-
-			if (found)
-				continue;
-
-			cmp = imageExtensions;
-			while (*cmp) {
-				if (strcmp(*cmp, suffix) == 0) {
-					AddDropSource(QT_TO_UTF8(file),
-							DropType_Image);
-					found = true;
-					break;
-				}
-
-				cmp++;
-			}
-
-			if (found)
-				continue;
-
-			cmp = mediaExtensions;
-			while (*cmp) {
-				if (strcmp(*cmp, suffix) == 0) {
-					AddDropSource(QT_TO_UTF8(file),
-							DropType_Media);
-					break;
-				}
-
-				cmp++;
-			}
+#define CHECK_SUFFIX(extensions, type) \
+cmp = extensions; \
+while (*cmp) { \
+	if (strcmp(*cmp, suffix) == 0) { \
+		AddDropSource(QT_TO_UTF8(file), type); \
+		found = true; \
+		break; \
+	} \
+\
+	cmp++; \
+} \
+\
+if (found) \
+	continue;
+
+			CHECK_SUFFIX(textExtensions, DropType_Text);
+			CHECK_SUFFIX(htmlExtensions, DropType_Html);
+			CHECK_SUFFIX(imageExtensions, DropType_Image);
+			CHECK_SUFFIX(mediaExtensions, DropType_Media);
+
+#undef CHECK_SUFFIX
 		}
 	} else if (mimeData->hasText()) {
 		AddDropSource(QT_TO_UTF8(mimeData->text()), DropType_RawText);

+ 2 - 1
UI/window-basic-main.hpp

@@ -102,7 +102,8 @@ class OBSBasic : public OBSMainWindow {
 		DropType_RawText,
 		DropType_Text,
 		DropType_Image,
-		DropType_Media
+		DropType_Media,
+		DropType_Html
 	};
 
 private: