Debian Codegraph @

editor/gui/editor_version_button.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_version_button.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "editor_version_button.h"
32
33 #include "core/os/time.h"
34 #include "core/version.h"
35
36 String _get_version_string(EditorVersionButton::VersionFormat p_format) {
37 String main;
38 switch (p_format) {
39 case EditorVersionButton::FORMAT_BASIC: {
40 return GODOT_VERSION_FULL_CONFIG;
41 } break;
42 case EditorVersionButton::FORMAT_WITH_BUILD: {
43 main = "v" GODOT_VERSION_FULL_BUILD;
44 } break;
45 case EditorVersionButton::FORMAT_WITH_NAME_AND_BUILD: {
46 main = GODOT_VERSION_FULL_NAME;
47 } break;
48 default: {
49 ERR_FAIL_V_MSG(GODOT_VERSION_FULL_NAME, "Unexpected format: " + itos(p_format));
50 } break;
51 }
52
53 String hash = GODOT_VERSION_HASH;
54 if (!hash.is_empty()) {
55 hash = vformat(" [%s]", hash.left(9));
56 }
57 return main + hash;
58 }
59
60 void EditorVersionButton::_notification(int p_what) {
61 switch (p_what) {
62 case NOTIFICATION_POSTINITIALIZE: {
63 // This can't be done in the constructor because theme cache is not ready yet.
64 set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
65 set_text(_get_version_string(format));
66 } break;
67
68 case NOTIFICATION_TRANSLATION_CHANGED: {
69 String build_date;
70 if (GODOT_VERSION_TIMESTAMP > 0) {
71 build_date = Time::get_singleton()->get_datetime_string_from_unix_time(GODOT_VERSION_TIMESTAMP, true) + " UTC";
72 } else {
73 build_date = TTR("(unknown)");
74 }
75 set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version information."), build_date));
76 } break;
77 }
78 }
79
80 void EditorVersionButton::pressed() {
81 DisplayServer::get_singleton()->clipboard_set(_get_version_string(FORMAT_WITH_BUILD));
82 }
83
84 EditorVersionButton::EditorVersionButton(VersionFormat p_format) {
85 format = p_format;
86 set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
87 }