package de.derpandaa.plinfa; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Properties; import de.derpandaa.plinfa.aiprovider.OpenAiProvider; import de.derpandaa.plinfa.dto.ChatDto; import io.qt.gui.QColor; import io.qt.gui.QIcon; import io.qt.gui.QPalette; import io.qt.gui.QPalette.ColorRole; import io.qt.widgets.QApplication; import io.qt.widgets.QHBoxLayout; import io.qt.widgets.QMainWindow; import io.qt.widgets.QVBoxLayout; import io.qt.widgets.QWidget; public class PlinfaWindow extends QMainWindow { public final static QColor colorBackground = new QColor(40, 42, 46); public final static QColor colorBackgroundAlt = new QColor(55, 59, 65); public final static QColor colorForeground = new QColor(208, 208, 208); private ChatWindow chatWindow; private QVBoxLayout vLayout; private QHBoxLayout hLayout; private PlinfaMenu menuBar; private Map chatMap; public PlinfaWindow() { super(); QPalette palette = getPalette(); palette.setColor(ColorRole.Window, colorBackground); palette.setColor(ColorRole.Base, colorBackgroundAlt); palette.setColor(ColorRole.Button, colorBackgroundAlt); palette.setColor(ColorRole.Text, colorForeground); palette.setColor(ColorRole.ButtonText, colorForeground); palette.setColor(ColorRole.PlaceholderText, colorForeground); setPalette(palette); QWidget mainWidget = new QWidget(); QWidget widget = new QWidget(); vLayout = new QVBoxLayout(mainWidget); menuBar = new PlinfaMenu(); menuBar.addButton(new QIcon("/usr/share/pandaaPop/img/brightness.svg"), null, "Test"); vLayout.addWidget(menuBar); hLayout = new QHBoxLayout(widget); vLayout.addWidget(widget); ChatListWidget chatListWidget = new ChatListWidget(chat -> loadChat(chat)); hLayout.addWidget(chatListWidget, 1); chatWindow = new ChatWindow(); hLayout.addWidget(chatWindow, 3); chatMap = new HashMap(); setCentralWidget(mainWidget); show(); } public void loadChat(ChatDto chatDto) { hLayout.removeWidget(chatWindow); chatWindow.hide(); ChatWindow cachedChatWindow = chatMap.get(chatDto); if (cachedChatWindow == null) { cachedChatWindow = new ChatWindow(chatDto); chatMap.put(chatDto, cachedChatWindow); } chatWindow = cachedChatWindow; hLayout.addWidget(chatWindow, 3); chatWindow.show(); } public static void main(String[] args) { QApplication.initialize(args); QApplication.setStyle("Fusion"); initProperties(); PlinfaWindow window = new PlinfaWindow(); QApplication.exec(); QApplication.shutdown(); } private static void initProperties() { Properties properties = new Properties(); try { properties.load(new FileInputStream("ai.properties")); } catch (FileNotFoundException e) { System.out.println("[ERROR] No Properties File"); System.exit(1); } catch (IOException e) { System.out.println("[ERROR] Cannot Access File"); System.exit(1); } OpenAiProvider.API_KEY = properties.getProperty("OPENAI_KEY"); ChatDto.PROJECT_DIR = properties.getProperty("PROJECT_DIR"); } }