def unload(self):
    """Unloads the plugin and cleans up the GUI."""
    # Remove the plugin menu items
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.signIn)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.searchGme)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.searchGallery)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.addWms)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.viewInGme)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.viewInGoogleMaps)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.shareSecureLink)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.upload)
    self.iface.removePluginMenu('&Google Maps Engine Connector',
                                self.showMore)

    # Remove the toolbar
    del self.toolBar

    # Revoke the token on exit
    oauth2_utils.revokeToken()
    # Remove the access credientials from settings
    settings.clear()
  def doSignInOrOut(self, checked):
    """Show the sign-in dialog and manage authentication status.

    Args:
      checked: bool, whether the sign-in action was checked.
    """
    if checked:
      # check if client_id and client_secret exist
      client_id = settings.read('gmeconnector/CLIENT_ID')
      client_secret = settings.read('gmeconnector/CLIENT_SECRET')
      if client_id and client_secret:
        token = oauth2_utils.getToken()
        if token:
          self.token = token
          self.handleAuthChange(True, token, '')
        else:
          # The sign-in dialog is initialized when the plugin is loaded.
          # We need to have setInitialUrl outside the dialog constructor to make
          # sure it's called everytime the sign-in button is clicked.
          self.signInDlg.setInitialUrl()
          result = self.signInDlg.exec_()
          if not result:
            self.handleAuthChange(False, None, '')
      else:
        self.signIn.setChecked(False)
        warnText = ('You must enter valid OAuth2.0 Client ID '
                    'and Client secret in Advanced Settings.')
        QMessageBox.warning(self.iface.mainWindow(), 'Warning', warnText)
        self.doShowMore()
    else:
      self.token = None
      self.signIn.setText('Logged out. Click to log in.')
      self.signIn.setChecked(False)
      self.disableAllTools()
      # Revoke the token
      oauth2_utils.revokeToken()
      # Remove the access credientials from settings
      settings.clear()