#
# Module for telling the user about important stuff after transition to another
# version.
#
# ~/.gdesklets/registry/version keeps the gDesklets version
#
# If it doesn't contain our version, we might want to tell the user something.
#

from main import USERHOME, VERSION
from utils import dialog

import os


#
# Compares the current gDesklets version with the version which previously ran
# and returns True if the versions match.
#
def _check_version():

    path = os.path.join(USERHOME, "registry", "version")
    try:
        version = open(path).read()
    except:
        version = "old :)"

    try:
        open(path, "w").write(VERSION)
    except:
        pass


    return (VERSION == version)




if (not _check_version()):
    if (VERSION.endswith("CVS")):
        # CVS warning :)
        msg = _("This is a CVS version of gDesklets. CVS versions represent " \
                "the current state of development and might be unstable or " \
                "cause problems from time to time.\n\n" \
                "If you're new to gDesklets, it is thus highly recommended to "
                "<b>not</b> use a CVS version, but a stable release!\n\n"
                "If you still want to run the CVS version instead of a "
                "stable release version, we'd highly appreciate it if you "
                "report any weird behavior to the developers.\n\n"
                "Experienced users are encouraged to try a CVS version, "
                "though!")

    elif ("rc" in VERSION):
        msg = _("This is a <b>release candidate</b> of an upcoming gDesklets "
                "release.\nPlease test it and report bugs to "
                "<i>http://bugzilla.gnome.org</i>\n"
                "This version might break your configuration or it won't "
                "restore it from an earlier release. In most cases this is "
                "intentional, since gDesklets is still in its early stages of "
                "development.\n\nThanks for testing this release candidate!")

    else:
        # our informative transition message which we can change with
        # every release
        msg = _("This version of gDesklets does no longer use the GConf "
                "database. If you don't plan to use an older version of "
                "gDesklets, you can safely remove the '/apps/gdesklets' "
                "folder from your GConf database.\n\n"
                "Due to the complete transition of the configuration data "
                "into the '~/.gdesklets' folder, gDesklets 0.35 will not "
                "make use of your previous configuration.\n\n"
                "Sorry if this should cause any inconveniences!")


    # show the dialog
    dialog.info(
        _("Please note (this message will appear only once):"),
        msg)
