Skip to content

Commit ba15c0a

Browse files
First files added
0 parents  commit ba15c0a

File tree

12 files changed

+344
-0
lines changed

12 files changed

+344
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# User-specific files
2+
*.suo
3+
*.user
4+
*.userosscache
5+
*.sln.docstates
6+
7+
# User-specific files (MonoDevelop/Xamarin Studio)
8+
*.userprefs
9+
10+
11+
# Build results
12+
[Bb]uild/
13+
.vs/
14+
.vscode/
15+
out/

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
4+
5+
################################################################################
6+
## PROJECT
7+
## name and version
8+
################################################################################
9+
project(SimpleFileDialog LANGUAGES CXX)
10+
11+
12+
13+
################################################################################
14+
## SETTINGS
15+
## basic project settings before use
16+
################################################################################
17+
# If this project is used as a submodule, the variable should be overridden
18+
# to "OFF" in the top-level application (to disable forced cache rewriting)
19+
option(${PARENT}_SUBMODULE_CACHE_OVERWRITE "Enable forced cache rewriting" ON)
20+
if (${PARENT}_SUBMODULE_CACHE_OVERWRITE)
21+
SET(REWRITE_FORCE "FORCE")
22+
else()
23+
SET(REWRITE_FORCE "")
24+
endif()
25+
26+
27+
28+
################################################################################
29+
## CONFIGURATION
30+
## project configuration
31+
################################################################################
32+
SET(${PARENT}_SIMPLE_FILE_DIALOG ON CACHE BOOL "" ${REWRITE_FORCE})
33+
SET(${PARENT}_SIMPLE_FILE_DIALOG_TEST ON CACHE BOOL "" ${REWRITE_FORCE})
34+
35+
36+
37+
################################################################################
38+
## INCLUDING SUBDIRECTORIES
39+
## Adding subdirectories according to the configuration
40+
################################################################################
41+
if (${PARENT}_SIMPLE_FILE_DIALOG)
42+
add_subdirectory(src)
43+
endif()
44+
45+
if (${PARENT}_SIMPLE_FILE_DIALOG_TEST)
46+
add_subdirectory(test)
47+
endif()

LICENSE.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright [2023] [ConstantRobotics Sp. z o.o]
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
![frame_logo](_static/file_dialog_logo.png)
2+
3+
# **Simple file dialog C++ library**
4+
5+
**v1.0.0**
6+
7+
------
8+
9+
# Overview
10+
11+
**SimpleFileDialog** C++ library provides simple dialog to chose file in Windows and Linux (tested for Ubuntu 22.04, 22.10 and Windows 11). The library used in projects when simple file chose dialog needed. To provide dialog in Linux the library calls "**zenity**" application. The library doesn't have third-party dependencies. **SimpleFileDialog.h** file includes declaration of **SimpleFileDialog** class. **SimpleFileDialog** class includes only one simple static method **dialod()**;
12+
13+
# Versions
14+
15+
**Table 1** - Library versions.
16+
17+
| Version | Release date | What's new |
18+
| ------- | ------------ | -------------- |
19+
| 1.0.0 | 20.07.2023 | First version. |
20+
21+
# Class description
22+
23+
**SimpleDileDialog** class declared in **SimpleFileDialog.h** file. Class declaration:
24+
25+
```cpp
26+
namespace cr
27+
{
28+
namespace utils
29+
{
30+
/// @brief File dialog class.
31+
class SimpleFileDialog
32+
{
33+
public:
34+
/// @brief Dialog function.
35+
static std::string dialog();
36+
};
37+
}
38+
}
39+
```
40+
41+
**SimpleFileDialog** class includes only one static method **dialog()** which shows file chose dialog to user. Method used without **SimpleFileDialog** class instance. Example:
42+
43+
```cpp
44+
#include <iostream>
45+
#include "SimpleFileDialog.h"
46+
47+
int main(void)
48+
{
49+
// Open file dialog.
50+
std::string file = cr::utils::SimpleFileDialog::dialog();
51+
std::cout << "File: " << file << std::endl;
52+
53+
return -1;
54+
}
55+
```

_static/file_dialog_logo.png

57.8 KB
Loading

src/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
4+
5+
################################################################################
6+
## LIBRARY-PROJECT
7+
## name and version
8+
################################################################################
9+
project(SimpleFileDialog VERSION 1.0.0 LANGUAGES CXX)
10+
11+
12+
13+
################################################################################
14+
## SETTINGS
15+
## basic project settings before use
16+
################################################################################
17+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
18+
set(CMAKE_CXX_STANDARD 17)
19+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
20+
# Enabling export of all symbols to create a dynamic library
21+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
22+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
23+
# creating output directory architecture in accordance with GNU guidelines
24+
set(BINARY_DIR "${CMAKE_BINARY_DIR}")
25+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BINARY_DIR}/bin")
26+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BINARY_DIR}/lib")
27+
file (GLOB_RECURSE IN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h.in)
28+
configure_file(${IN_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Version.h)
29+
30+
31+
32+
################################################################################
33+
## TARGET
34+
## create target and add include path
35+
################################################################################
36+
# create glob files for *.h, *.cpp
37+
file (GLOB_RECURSE H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
38+
file (GLOB_RECURSE CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
39+
# concatenate the results (glob files) to variable
40+
set (SOURCES ${CPP_FILES} ${H_FILES})
41+
# create lib from src
42+
if (NOT TARGET ${PROJECT_NAME})
43+
add_library(${PROJECT_NAME} STATIC ${SOURCES})
44+
endif()
45+
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
46+

src/SimpleFileDialog.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#if defined(linux) || defined(__linux) || defined(__linux__)
2+
#include <cstdint>
3+
#else
4+
#include <Windows.h>
5+
#include <shobjidl.h>
6+
#endif
7+
#include <cstring>
8+
#include <string.h>
9+
#include "SimpleFileDialog.h"
10+
11+
12+
13+
std::string cr::utils::SimpleFileDialog::dialog()
14+
{
15+
#if defined(linux) || defined(__linux) || defined(__linux__)
16+
char filename[1024];
17+
FILE *f = popen("zenity --file-selection", "r");
18+
fgets(filename, 1024, f);
19+
filename[strlen(filename) - 1] = 0;
20+
string file(filename);
21+
return file;
22+
#else
23+
IFileOpenDialog* pFileOpen = nullptr;
24+
HRESULT hr;
25+
PWSTR file;
26+
char* filename;
27+
28+
hr = CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
29+
if (SUCCEEDED(hr))
30+
{
31+
hr = CoCreateInstance(CLSID_FileOpenDialog,
32+
NULL, CLSCTX_ALL,
33+
IID_IFileOpenDialog,
34+
(void**)&pFileOpen);
35+
if (SUCCEEDED(hr))
36+
{
37+
pFileOpen->SetTitle(L"OPEN VIDEO FILE");
38+
hr = pFileOpen->Show(NULL);
39+
if (SUCCEEDED(hr))
40+
{
41+
IShellItem* pItem;
42+
hr = pFileOpen->GetResult(&pItem);
43+
if (SUCCEEDED(hr))
44+
{
45+
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &file);
46+
if (SUCCEEDED(hr))
47+
{
48+
pItem->Release();
49+
int count = WideCharToMultiByte(
50+
CP_ACP, 0, file, (int)wcslen(file), 0, 0, NULL, NULL);
51+
filename = new char[(size_t)count + 1];
52+
WideCharToMultiByte(CP_ACP, 0, file, count, filename,
53+
count + 1, NULL, NULL);
54+
filename[(size_t)count] = '\0';
55+
std::string file(filename);
56+
delete[] filename;
57+
return file;
58+
}
59+
}
60+
pItem->Release();
61+
return "";
62+
}
63+
}
64+
}
65+
pFileOpen->Release();
66+
return "";
67+
#endif
68+
}

src/SimpleFileDialog.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include <string>
3+
4+
5+
6+
namespace cr
7+
{
8+
namespace utils
9+
{
10+
/// @brief File dialog class.
11+
class SimpleFileDialog
12+
{
13+
public:
14+
/// @brief Dialog function.
15+
static std::string dialog();
16+
};
17+
}
18+
}
19+
20+
21+

src/SimpleFileDialogVersion.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define SIMPLE_FILE_DIALOG_MAJOR_VERSION 1
4+
#define SIMPLE_FILE_DIALOG_MINOR_VERSION 0
5+
#define SIMPLE_FILE_DIALOG_PATCH_VERSION 0
6+
7+
#define SIMPLE_FILE_DIALOG_VERSION "1.0.0"

src/SimpleFileDialogVersion.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define SIMPLE_FILE_DIALOG_MAJOR_VERSION @PROJECT_VERSION_MAJOR@
4+
#define SIMPLE_FILE_DIALOG_MINOR_VERSION @PROJECT_VERSION_MINOR@
5+
#define SIMPLE_FILE_DIALOG_PATCH_VERSION @PROJECT_VERSION_PATCH@
6+
7+
#define SIMPLE_FILE_DIALOG_VERSION "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"

0 commit comments

Comments
 (0)