def initConfig(self):
        kate.debug("initConfig()")
        config_path = kate.pate.pluginDirectories[1] + "/%s/%s.conf" % (__name__, __name__)
        config_file = QFileInfo(config_path)

        if not config_file.exists():
            open(config_path, "w").close()

        config = ConfigParser()
        config.read(config_path)

        # init the DEFAULT options if they don't exist
        # the DEFAULT section is special and doesn't need to be created: if not config.has_section('DEFAULT'): config.add_section('DEFAULT')
        if not config.has_option("DEFAULT", "ignore"):
            config.set("DEFAULT", "ignore", "")
        if not config.has_option("DEFAULT", "filter"):
            config.set("DEFAULT", "filter", "*")
        if not config.has_option("DEFAULT", "finder_size"):
            config.set("DEFAULT", "finder_size", "400x450")
        if not config.has_option("DEFAULT", "config_size"):
            config.set("DEFAULT", "config_size", "300x350")
        if not config.has_option("DEFAULT", "search_type"):
            config.set("DEFAULT", "search_type", "word")

        # create the general section if it doesn't exist
        if not config.has_section("general"):
            config.add_section("general")

        # flush the config file
        config.write(open(config_path, "w"))

        # save the config object and config path as instance vars for use later
        self.config = config
        self.config_path = config_path
    def reload(self):

        # sanity checks
        if not self.sanityChecks(self.open_project):
            return

        # clear the widgets
        self.browser.clear()
        self.finder.clear()

        # parse the ignore list (used further down the call stack)
        self.ignore_list = self.get_option("ignore")
        if self.ignore_list:
            self.ignore_list = [x.strip() for x in self.ignore_list.split(",")]
        else:
            self.ignore_list = []

        # init the dir watcher
        self.dir_watcher = KDirWatch()
        QObject.connect(self.dir_watcher, SIGNAL("dirty ( const QString & )"), self.dirDirtied)
        QObject.connect(self.dir_watcher, SIGNAL("deleted ( const QString & )"), self.dirRemoved)

        # time and output the building of the tree
        t1 = time()
        self.addItem(QFileInfo(self.open_project), self.browser)
        kate.debug("project (re)load took %f seconds" % (time() - t1))
 def menuClose(self):
     kate.debug("menuClose()")
     self.browser.clear()
     self.finder.clear()
     self.open_project = None
     self.config.set("general", "last", "")
     self.saveConfig()
 def menuClose(self):
   kate.debug('menuClose()')
   self.browser.clear()
   self.finder.clear()
   self.open_project = None
   self.config.set('general', 'last', '')
   self.saveConfig()
    def openProject(self, project_path):

        # clean up the input
        project_path = str(project_path).strip()

        # sanity checks
        if not self.sanityChecks(project_path):
            return

        # little debug info
        kate.debug("opening new project: " + project_path)

        # set the open project
        self.open_project = project_path

        # init its config section if need be
        if not self.config.has_section(project_path):
            self.config.add_section(project_path)

        # update the last open project in the config section
        self.config.set("general", "last", project_path)

        # write the config so we always stay in sync
        self.saveConfig()

        # build the project tree!
        self.reload()
 def sanityChecks(self, project_path):
     file_info = QFileInfo(project_path)
     if not file_info.exists():
         kate.debug("project dir does not exist: %s" % project_path)
         return False
     if not file_info.isDir():
         kate.debug("project dir is not a directory: %s" % project_path)
         return False
     return True
 def set(lvi, path, is_dir=False):
     if is_dir:
         if not PixmapSetter.dir_pixmap:
             kate.debug("caching directory pixmap")
             PixmapSetter.dir_pixmap = KMimeType.findByPath(path).pixmap(KIcon.Small)
         pixmap = PixmapSetter.dir_pixmap
     else:
         pixmap = KMimeType.findByPath(path, 0, True).pixmap(KIcon.Small)
     lvi.setPixmap(0, pixmap)
 def openItems(self, items):
   for item in items:
     if not item: continue # what the hell?  something is broken
     if item.is_dir == False:
       kate.debug("file dbl clicked")
       kate.documentManager.open(item.path)
       d = kate.documentManager.get(item.path)
       kate.application.activeMainWindow().viewManager().activateView(d.number)
       self.finder.close()
     else:
       kate.debug("dir dbl clicked")
       self.browser.setOpen(item, not self.browser.isOpen(item))
    def closeEvent(self, e):
        x, y = self.width(), self.height()
        x, y = int(x), int(y)

        old_x, old_y = self.dp.config.get("general", "finder_size").split("x")
        old_x, old_y = int(old_x), int(old_y)

        if x != old_x or y != old_y:
            kate.debug("saving new finder dialog size: %dx%d" % (x, y))
            self.dp.config.set("general", "finder_size", "%dx%d" % (x, y))
            self.dp.saveConfig()

        # default implementation...
        e.accept()
    def updateSearch(self, s=None):
        t1 = time()

        search_type = self.listView().parent().dp.config.get("general", "search_type").lower()
        if search_type == "exact":
            self.updateSearch_exact(s)
        elif search_type == "char":
            self.updateSearch_char(s)
        elif search_type == "word":
            self.updateSearch_word(s)
        else:
            kate.debug("unexpected search type: %s" % search_type)
            return

        kate.debug("updateSearch(%s): %f seconds for %d items" % (s, time() - t1, self.listView().childCount()))

        self.resetListView()
  def updateSearch(self, s = None):
    t1 = time()

    search_type = self.listView().parent().dp.config.get('general', 'search_type').lower()
    if search_type == 'exact':
      self.updateSearch_exact(s)
    elif search_type == 'char':
      self.updateSearch_char(s)
    elif search_type == 'word':
      self.updateSearch_word(s)
    else:
      kate.debug("unexpected search type: %s" % search_type)
      return

    kate.debug('updateSearch(%s): %f seconds for %d items' % (s, time()-t1, self.listView().childCount()))
    
    self.resetListView()
 def keyPressEvent(self, event):
     kate.debug("event: " + str(event.key()))
     if event.key() == Qt.Key_Up:
         if self.list_view.selectedItem():
             self.list_view.keyPressEvent(event)
         else:
             self.selectLastItem()
     elif event.key() == Qt.Key_Down:
         if self.list_view.selectedItem():
             self.list_view.keyPressEvent(event)
         else:
             self.selectFirstItem()
     elif event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
         self.dp.openItems((self.list_view.selectedItem(),))
     elif event.key() == Qt.Key_Escape:
         if not str(self.lv_search.searchLine().text()):
             self.close()
         else:
             self.lv_search.searchLine().clear()
     else:
         event.ignore()
    def dirDirtied(self, path):
        path = str(path)
        kate.debug("dirDirtied: " + path)

        # find the list view item for the watched directory
        lvi = self.browser.findItem(path, 1)
        if not lvi:
            kate.debug("cannot find directory: " + path)
            return

        # create a set of all it's children
        our_set = set()
        p = lvi.firstChild()
        while p:
            our_set.add(str(p.text(1)))
            p = p.nextSibling()

        # create a set of all the actual directory's children
        real_set = set()
        d = QDir(path)
        for file_info in d.entryInfoList():
            if file_info.fileName() == ".":
                continue
            if file_info.fileName() == "..":
                continue
            real_set.add(str(file_info.absFilePath()))

        # difference the set and those are our adds
        set_diff = real_set.difference(our_set)
        for path in set_diff:
            file_info = QFileInfo(path)
            self.addItem(file_info, lvi)
        kate.debug("added files/dirs: " + str(set_diff))

        # differece the other way and those are our deletes
        set_diff = our_set.difference(real_set)
        kate.debug("removing files/dirs: " + str(set_diff))
        for path in set_diff:
            self.removeItem(path)
 def menuSettings(self):
     kate.debug("menuSettings()")
     self.settings.show()
 def menuReload(self):
     kate.debug("menuReload()")
     if self.open_project:
         self.reload()
     else:
         KMessageBox.information(kate.mainWidget(), "There is no project open to reload.", "No Project Open")
 def menuFindFiles(self):
     kate.debug("menuFindFiles()")
     if not self.open_project:
         KMessageBox.information(kate.mainWidget(), "Open a project first.", "No Project Open")
     else:
         self.finder.show()
 def menuSettings(self):
   kate.debug('menuSettings()')
   self.settings.show()
 def menuOpen(self):
     kate.debug("menuOpen()")
     project_path = KFileDialog.getExistingDirectory()
     if project_path:
         self.openProject(project_path)
 def dirRemoved(self, path):
     kate.debug("dirRemoved: " + str(path))
 def dirRemoved(self, path):
   kate.debug('dirRemoved: ' + str(path))