Пример #1
0
 def on_blacklist(self, evt):
     """end application"""
     peer_id = self.other_tab.get_peer_selected()
     if peer_id:
         get_facade().blacklist_peer(peer_id)
     else:
         display_warning("no peer selected")
Пример #2
0
 def remove_blog(self):
     assert get_facade(), "Facade not initialiazed"
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         get_facade().remove_blog(selected)
     else:
         display_warning(_("none selected"))
Пример #3
0
 def Disable(self):
     """It is called when the user chooses to disable the service."""
     # ask for saving (ca not simply call Close() on editor frame
     # method because of multithreading and the frame is destroyed
     # before the user actually answer to the popup
     if self.editor_frame and self.editor_frame.modified:
         import wx
         self.editor_frame.do_modified(False)
         dlg = wx.MessageDialog(
             self.editor_frame,
             'Your profile has been modified. Do you want to save it?',
             'Saving Profile',
             wx.YES_NO | wx.ICON_INFORMATION)
         if dlg.ShowModal() == wx.ID_YES:
             get_facade()._desc.save()
     if self.filter_frame and self.filter_frame.modified:
         import wx
         self.filter_frame.do_modified(False)
         dlg = wx.MessageDialog(
             self.filter_frame,
             'Your filters have been modified. Do you want to save them?',
             'Saving Filters',
             wx.YES_NO | wx.ICON_INFORMATION)
         if dlg.ShowModal() == wx.ID_YES:
             get_filter_facade().save()
     self.activate(False)
Пример #4
0
 def refresh(self, files=None):
     """overrides Show, files is {repos: [FileDescriptors], }"""
     if not self.IsShown():
         return
     if files is None:
         if get_facade() is None:
             return
         files = get_facade()._desc.document.get_shared_files()
     # clear previous data
     self.peerfiles_list.DeleteAllItems()
     for key in self.data.keys():
         del self.data[key]
     # fill new data
     for file_container in files.flatten():
         path = file_container.get_path()
         index = self.peerfiles_list.InsertStringItem(
             sys.maxint, force_unicode(file_container.name))
         self.peerfiles_list.SetStringItem(index, TAG_COL, file_container._tag)
         self.peerfiles_list.SetStringItem(index, SIZE_COL,
                                           formatbytes(file_container.size,
                                                       kiloname="Ko",
                                                       meganame="Mo",
                                                       bytename="o"))
         self.data[index] = (path.split(os.sep), file_container.size)
     # show result
     self.peerfiles_list.SetColumnWidth(TAG_COL, wx.LIST_AUTOSIZE)
Пример #5
0
 def on_anonymous(self, evt):
     """end application"""
     peer_id = self.other_tab.get_peer_selected()
     if peer_id:
         get_facade().unmark_peer(peer_id)
     else:
         display_warning("no peer selected")
Пример #6
0
 def on_close(self, evt):
     """hide  application"""
     get_facade()._desc.save()
     if self.options["standalone"]:
         self._close()
     else:
         self.Hide()
Пример #7
0
 def on_make_friend(self, evt):
     """end application"""
     peer_id = self.other_tab.get_peer_selected()
     if peer_id:
         get_facade().make_friend(peer_id)
     else:
         display_warning("no peer selected")
Пример #8
0
 def ChangedNode(self, node):
     """need to update node_id"""
     # ChangedNode is call more than one time on change. Thus, be
     # careful not to do the job every time
     log("ChangedNode", node.pseudo)
     if get_facade() is None or get_facade()._desc.document.get_pseudo() != node.pseudo:
         # creation
         facade = create_facade(node.id_)
         filter_facade = create_filter_facade(node.id_)
         if not facade.load():
             log(
                 _(u"You have no profile yet for pseudo %s."% node.pseudo))
         if not filter_facade.load():
             log(
                 _(u"You have no filters defined yet for pseudo %s."% node.pseudo))
         facade.change_pseudo(node.pseudo)
         # updating views
         if self.editor_frame:
             facade.add_view(EditorView(facade._desc,
                                        self.editor_frame))
             self.editor_frame.on_change_facade()
             facade.add_view(ViewerView(facade._desc,
                                        self.viewer_frame))
             self.viewer_frame.on_change_facade()
         if self.filter_frame:
             filter_facade.add_view(FilterView(filter_facade._desc,
                                               self.filter_frame))
             self.filter_frame.on_change_facade()
         log(_("Loaded data for %s"% node.pseudo))
Пример #9
0
 def add_comment(self, text):
     """store blog in cache as wx.HtmlListBox is virtual"""
     assert get_facade(), "Facade not initialiazed"
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         get_facade().add_comment(selected, text, get_facade()._desc.document.get_pseudo())
     else:
         display_warning(_("none selected"))
Пример #10
0
 def OnGetItem(self, n):
     """callback to display item"""
     assert get_facade(), "Facade not initialiazed"
     try:
         return get_facade()._desc.blog.get_blog(n).html()
     except IndexError, err:
         display_error(_('Could not get blog.'), error=err)
         return "<p>Corrupted Blog</p>"
Пример #11
0
 def DoPointToPointAction(self, it, peer, deferred=None):
     """Called when a point-to-point action is invoked, if available."""
     if get_facade() and get_facade()._activated:
         # retreive corect method
         actions = self.POINT_ACTIONS.values()
         # call method on peer
         actions[it](peer.id_, deferred)
     # service not activated, do nothing
     else:
         print "service not activated"
Пример #12
0
 def on_export(self, evt):
     """export .html"""
     dlg = wx.FileDialog(
         self, message="Export HTML file as ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="HTML File (*.html)|*.html",
         style=wx.SAVE)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         get_facade().export_profile(path)
Пример #13
0
 def on_export(self, evt):
     """export .html"""
     dlg = wx.FileDialog(
         self, message=_("Export HTML file as ..."),
         defaultDir=get_prefs("profile_dir"),
         defaultFile="%s.html"% get_facade()._desc.document.get_pseudo(),
         wildcard=_("HTML File (*.html)|*.html"),
         style=wx.SAVE)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         get_facade().export_profile(path)
Пример #14
0
    def execute(self, message):
        log("*exec*: ", message, self.peer_server.peer.peer_id)
        transport = self.peer_server.protocol.transport

        def on_failure(reason, transfert):
            log("transfert of %s failed: %s" % (transfert, str(reason)))
            transport.loseConnection()

        def on_success(result, transfert):
            log("transfert of %s complete" % transfert)
            transport.loseConnection()

        if message.command in [MESSAGE_HELLO, MESSAGE_PROFILE]:
            file_obj = get_facade()._desc.document.to_stream()
            deferred = basic.FileSender().beginFileTransfer(file_obj, transport)
            deferred.addCallback(on_success, "profile")
            deferred.addErrback(on_failure, "profile")
        elif message.command == MESSAGE_BLOG:
            blog_stream = get_facade().get_blog_file()
            deferred = basic.FileSender().beginFileTransfer(blog_stream, transport)
            deferred.addCallback(on_success, "blog")
            deferred.addErrback(on_failure, "blog")
        elif message.command == MESSAGE_SHARED:
            files_stream = get_facade().get_shared_files()
            deferred = basic.FileSender().beginFileTransfer(files_stream, transport)
            deferred.addCallback(on_success, "shared files")
            deferred.addErrback(on_failure, "shared files")
        elif message.command == MESSAGE_FILES:
            split_path, file_size = extract_data_file(message.data)
            file_name = os.sep.join(split_path)
            try:
                file_desc = get_facade().get_file_container(file_name)
                # check shared
                if file_desc._shared:
                    display_status("sending %s" % file_name)
                    deferred = basic.FileSender().beginFileTransfer(open(file_name, "rb"), transport)

                    deferred.addCallback(on_success, file_name)
                    deferred.addErrback(on_failure, file_name)
                else:
                    self.peer_server.protocol.factory.send_udp_message(
                        self.peer_server.peer.peer_id, MESSAGE_ERROR, message.data
                    )
                    SecurityAlert(self.peer_server.peer.peer_id, "Trying to download unshare file %s" % file_name)
            except ContainerException:
                SecurityAlert(self.peer_server.peer.peer_id, "Trying to download unvalid file %s" % file_name)
        else:
            SecurityAlert(self.peer_server.peer.peer_id, "ERROR in _connect: %s not valid" % message.command)
Пример #15
0
 def set_tab(self, peer_id):
     """add or update tab with preview of given peer"""
     peer_desc = get_facade().get_peer(peer_id)
     if peer_desc.node_id in self.tabs:
         self._update_tab(peer_desc)
     else:
         self._add_tab(peer_desc)
Пример #16
0
 def on_del(self, evt):
     """a custom attribute has been modified"""
     index = -1
     selected = []
     for counter in range(self.custom_list.GetSelectedItemCount()):
         index = self.custom_list.GetNextItem(index, state=wx.LIST_STATE_SELECTED)
         selected.append(index)
     # reverse deletion
     selected.sort()
     selected.reverse()
     for index in selected:
         item_text = self.custom_list.GetItemText(index)
         if self.custom_list.DeleteItem(index):
             # update cache
             get_facade().del_custom_attributes(item_text)
         self.do_modified(True)
Пример #17
0
 def on_import(self, event):
     """match current filter with given profile"""
     dlg = wx.FileDialog(
         self, message="Match profile ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()[:-4]
         loader = FileDocument()
         loader.load(path + PROFILE_EXT)
         get_facade().fill_data(loader.get_pseudo(), loader)
         get_filter_facade().match(PeerDescriptor(loader.get_pseudo(),
                                                  document = loader))
     event.Skip()
Пример #18
0
 def get_tab_index(self, peer_id):
     peer_desc = get_facade().get_peer(peer_id)
     if peer_id in self.tabs:
         for index in range(self.preview_notebook.GetPageCount()):
             if self.preview_notebook.GetPage(index).pseudo \
                    == peer_desc.document.get_pseudo():
                 return index
     return -1
Пример #19
0
 def add_comment(self, text):
     """store blog in cache as wx.HtmlListBox is virtual"""
     selected = self.GetSelection()
     if selected != wx.NOT_FOUND:
         pseudo = get_facade()._desc.document.get_pseudo()
         self.blog.add_comment(selected, text, pseudo)
         self.refresh()
     else:
         display_warning(_("none selected"))
 def test_downloads(self):
     def _on_test_profile(result):
         self.assert_(result)
         self.assert_profile(result)
     deferred = self.network.get_profile("boby")
     util.wait(deferred.addCallbacks(_on_test_profile, on_error))
     def _on_test_blog(result):
         self.assert_(result)
         self.assert_blog(result)
     deferred = self.network.get_blog_file("boby")
     util.wait(deferred.addCallbacks(_on_test_blog, on_error))
     def _on_test_shared_files(result):
         self.assert_(result)
         self.assert_files(result)
     deferred = self.network.get_shared_files("boby")
     util.wait(deferred.addCallbacks(_on_test_shared_files, on_error))
     def _on_test_files(result):
         file_name = os.path.join(GENERATED_DIR, "arc en ciel 6.gif")
         self.assert_(os.path.exists(file_name))
         self.assertEquals(163564, os.stat(file_name)[6])
         file_name = os.path.join(GENERATED_DIR, "02_b_1280x1024.jpg")
         self.assert_(os.path.exists(file_name))
         self.assertEquals(629622, os.stat(file_name)[6])
         file_name = os.path.join(GENERATED_DIR, "pywin32-203.win32-py2.3.exe")
         self.assert_(os.path.exists(file_name))
         self.assertEquals(3718120, os.stat(file_name)[6])
         file_name = os.path.join(GENERATED_DIR, "Python-2.3.5.zip")
         self.assert_(os.path.exists(file_name))
         self.assertEquals(9769010, os.stat(file_name)[6])
     get_facade().share_files(DATA_DIR,
                              ["arc en ciel 6.gif",
                               "02_b_1280x1024.jpg",
                               "pywin32-203.win32-py2.3.exe",
                               "Python-2.3.5.zip"],
                              share=True)
     set_prefs("download_repo", GENERATED_DIR)
     deferred = self.network.get_files("boby", [
         (DATA_DIR.split(os.sep) + ["arc en ciel 6.gif"], 163564),
         (DATA_DIR.split(os.sep) + ["02_b_1280x1024.jpg"], 629622),
         (DATA_DIR.split(os.sep) + ["pywin32-203.win32-py2.3.exe"], 3718120),
         (DATA_DIR.split(os.sep) + ["Python-2.3.5.zip"], 9769010)])
     return deferred.addCallbacks(_on_test_files, on_error)
Пример #21
0
 def on_get_blog(self, evt):
     """display peer's blog"""
     peer_id = self.other_tab.get_peer_selected()
     if peer_id:
         peer_desc = get_facade().get_peer(peer_id)
         if peer_desc.connected:
             self.plugin.get_blog_file(peer_id)
         else:
             display_status(peer_desc.node_id, "not connected")
             self.display_blog(peer_desc)
     else:
         display_warning("no peer selected")
Пример #22
0
 def on_get_files(self, evt):
     """display peer's files"""
     peer_id = self.other_tab.get_peer_selected()
     if peer_id:
         peer_desc = get_facade().get_peer(peer_id)
         if peer_desc.connected:
             self.plugin.select_files(peer_id)
         else:
             display_status(peer_desc.node_id, "not connected")
             self.display_files(peer_desc)
     else:
         "no peer selected"
Пример #23
0
 def on_photo(self, evt):
     """photo clicked"""
     dlg = wx.FileDialog(
         self, message=_("Choose your picture"),
         defaultDir=os.getcwd(), 
         defaultFile="",
         wildcard= _("Image GIF (*.gif)|*.gif|" \
         "Image JPEG (*.jpg)|*.jpg|" \
         "Image PNG (*.png)|*.png|" \
         "All files (*.*)|*.*"),
         style=wx.OPEN | wx.CHANGE_DIR )
     
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         if get_facade().change_photo(path) != False:
             self.do_modified(True)
     dlg.Destroy()
Пример #24
0
 def on_add(self, evt):
     dlg = wx.FileDialog(
         self, message="Add profile ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         directory, file_name = os.path.split(dlg.GetPath()[:-4])
         peer_desc = PeerDescriptor(file_name, document=FileDocument())
         peer_desc.load(directory=directory)
         blogs = peer_desc.blog
         loader = peer_desc.document
         get_facade().fill_data(peer_desc.node_id, loader)
         get_facade().fill_blog(peer_desc.node_id, blogs)
         get_facade().fill_shared_files(peer_desc.node_id, loader.get_shared_files())
         self.display_profile(peer_desc)
         self.display_blog(peer_desc)
         self.display_files(peer_desc)
Пример #25
0
 def on_lastname(self, evt):
     """lastname loses focus"""
     if get_facade().change_lastname(evt.GetEventObject().GetValue()) != False:
         self.do_modified(True)
     evt.Skip()
Пример #26
0
 def on_change_facade(self):
     """setter"""
     self.nickname_value.SetValue(get_facade()._desc.document.get_pseudo())
Пример #27
0
 def on_title(self, evt):
     """language loses focus"""
     if get_facade().change_title(evt.GetString()) != False:
         self.do_modified(True)
     evt.Skip()
Пример #28
0
 def on_connect(result):
     src_path = pseudo + PROFILE_EXT
     dst_path = os.path.join(PROFILE_DIR, get_facade()._desc.node_id + PROFILE_EXT)
     shutil.copyfile(src_path, dst_path)
     get_facade().load()
     print src_path, ">", dst_path
Пример #29
0
def get_filter_facade():
    """implements pattern singleton on FilterFacade"""
    if FilterFacade.filter_facade == None and get_facade() != None:
        create_filter_facade(get_facade()._desc.node_id)
    return FilterFacade.filter_facade
Пример #30
0
 def on_add(self, evt):
     """a custom attribute has been modified"""
     # update cache, facade will refresh window (through GuiView)
     get_facade().add_custom_attributes(self.key_value.GetValue(),
                                        self.custom_value.GetValue())
     self.do_modified(True)