import os
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtGui import QIcon



class WaystonesCloudPlugin:
    def __init__(self, iface):
        self.iface = iface
        self.action = None
        self.dialog = None

    def initGui(self):
        icon_path = os.path.join(os.path.dirname(__file__), "resources", "icon.png")
        self.action = QAction(QIcon(icon_path), "Publish to Waystones Cloud", self.iface.mainWindow())
        self.action.triggered.connect(self.run)
        self.iface.addToolBarIcon(self.action)
        self.iface.addPluginToWebMenu("Waystones Cloud", self.action)

    def unload(self):
        self.iface.removeToolBarIcon(self.action)
        self.iface.removePluginWebMenu("Waystones Cloud", self.action)

    def run(self):
        from .dialog import WaystonesDialog
        if self.dialog is None:
            self.dialog = WaystonesDialog(self.iface)
        self.dialog.show()
        self.dialog.raise_()
        self.dialog.activateWindow()
