예제 #1
0
class VcodeDialog(Gtk.Dialog):
    __metaclass__ = Singleton

    def __init__(self, parent, url):
        Gtk.Dialog.__init__(
            self,
            "Verification Code",
            parent,
            0,
        )
        self.file_list = []
        #self.downlink = []
        #self.tokens = tokens
        self.url = url
        #self.bdstoken,sign1,sign3,timestamp = self.tokens
        self.vcodefile = "image/vcode.jpeg"
        self.set_default_size(300, 200)
        self.set_border_width(10)
        label = Gtk.Label("Please input verification code above to proceed.")
        self.spinn = SpinnerDialog(self)
        self.spinn.show()
        self.vcodeimg = Gtk.Image.new()

        self.box = self.get_content_area()
        self.entry = Gtk.Entry()
        self.entry.connect("activate", self.on_enter_entry)
        self.entry.set_can_focus(True)
        self.entry.grab_focus()
        self.liststore = Gtk.ListStore(GdkPixbuf.Pixbuf)
        pix = GdkPixbuf.Pixbuf.new_from_file("image/loading.gif")
        self.liststore.append([pix])
        iconview = Gtk.IconView.new()
        iconview.set_model(self.liststore)
        iconview.set_pixbuf_column(0)
        #self.liststore.append([pix])
        self.show_vcode("image/loading.gif", None)  #"image/loading.gif",

        self.box.add(iconview)
        #pix = GdkPixbuf.Pixbuf.new_from_file("image/loading.gif")
        #Gtk.Image.new_from_pixbuf(pix)
        button = Gtk.Button("Refresh Code")
        button.connect("clicked", self.on_click_refresh_clicked)
        self.on_click_refresh_clicked(button)

        #self.entry.set_text("Input vcode above")

        self.okbtn = self.add_button("OK", 22)
        self.okbtn.connect("clicked", self.on_click_OK_clicked)
        self.box.set_child_packing(button, False, False, 1, Gtk.PackType.START)

        self.box.set_spacing(8)
        self.box.add(label)

        self.box.add(self.entry)
        self.box.add(button)
        #self.box.add(okbtn)

        self.box.show_all()

    def on_enter_entry(self, *arg):
        self.okbtn.clicked()

    def on_click_refresh_clicked(self, *arg):
        utils.async_call(self.download_vcodeimg,
                         self.url,
                         self.vcodefile,
                         callback=self.show_vcode)

    def new_url(self, url):
        self.url = url

    def on_click_OK_clicked(self, *arg):
        if not self.entry.get_text().strip():
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
                                       Gtk.ButtonsType.OK, "Attention.......")
            dialog.format_secondary_text("Nothing is input!")
            dialog.run()
            dialog.destroy()
            return

    def get_user_input(self, *arg):
        print(arg)
        inputtxt = self.entry.get_text().strip()

        return inputtxt

    def download_vcodeimg(self, imgurl, vcodeimg):
        f = open(vcodeimg, "wb")
        fp = fetch(imgurl, {}, "GetVcode")
        f.write(fp)
        f.close()
        return vcodeimg

    def show_vcode(self, imgfile, error):
        print('filename:', imgfile, error)
        pix = GdkPixbuf.Pixbuf.new_from_file(imgfile)
        fmat = GdkPixbuf.Pixbuf.get_file_info(imgfile)
        print(fmat[0].get_description(), fmat[0].get_extensions(),
              fmat[0].get_mime_types())
        print(pix)
        #if not self.vcodeimg:
        #self.vcodeimg.clear()
        #self.vcodeimg = Gtk.Image.new_from_pixbuf(pix)
        path = Gtk.TreePath(0)
        #self.liststore.append([pix])
        treeiter = self.liststore.get_iter(path)
        self.liststore.set_value(treeiter, 0, pix)
        #else:
        #	self.vcodeimg = Gtk.Image.set_from_pixbuf(pix)
        #self.vcodeimg.show()

        self.spinn.destroy()
예제 #2
0
class VcodeDialog(Gtk.Dialog):
	__metaclass__ = Singleton
	def __init__(self,parent,url):
		Gtk.Dialog.__init__(self, "Verification Code", parent, 0,)
		self.file_list = []
		#self.downlink = []
		#self.tokens = tokens
		self.url = url
		#self.bdstoken,sign1,sign3,timestamp = self.tokens
		self.vcodefile = "image/vcode.jpeg"
		self.set_default_size(300, 200)
		self.set_border_width(10)
		label = Gtk.Label("Please input verification code above to proceed.")
		self.spinn = SpinnerDialog(self)
		self.spinn.show()
		self.vcodeimg = Gtk.Image.new()

		self.box = self.get_content_area()
		self.entry = Gtk.Entry()
		self.entry.connect("activate",self.on_enter_entry)
		self.entry.set_can_focus(True)
		self.entry.grab_focus()
		self.liststore = Gtk.ListStore(GdkPixbuf.Pixbuf)
		pix = GdkPixbuf.Pixbuf.new_from_file("image/loading.gif")
		self.liststore.append([pix])
		iconview = Gtk.IconView.new()
		iconview.set_model(self.liststore)
		iconview.set_pixbuf_column(0)
		#self.liststore.append([pix])
		self.show_vcode("image/loading.gif",None)#"image/loading.gif",
	
		self.box.add(iconview)
		#pix = GdkPixbuf.Pixbuf.new_from_file("image/loading.gif")
		 #Gtk.Image.new_from_pixbuf(pix)
		button = Gtk.Button("Refresh Code")
		button.connect("clicked", self.on_click_refresh_clicked)
		self.on_click_refresh_clicked(button)

	
		#self.entry.set_text("Input vcode above")

		self.okbtn = self.add_button("OK", 22)
		self.okbtn.connect("clicked", self.on_click_OK_clicked)
		self.box.set_child_packing(button,False,False,1,Gtk.PackType.START)

		self.box.set_spacing(8)
		self.box.add(label)
		
		self.box.add(self.entry)
		self.box.add(button)
		#self.box.add(okbtn)
		
		self.box.show_all()

	def on_enter_entry(self,*arg):
		self.okbtn.clicked()
	def on_click_refresh_clicked(self,*arg):
		utils.async_call(self.download_vcodeimg,self.url,self.vcodefile,
						 callback=self.show_vcode)
	def new_url(self,url):
		self.url = url
	def on_click_OK_clicked(self,*arg):
		if not self.entry.get_text().strip():
			dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, "Attention.......")
			dialog.format_secondary_text("Nothing is input!")
			dialog.run()
			dialog.destroy()
			return
		
	def get_user_input(self,*arg):
		print(arg)
		inputtxt = self.entry.get_text().strip()

		return inputtxt
	def download_vcodeimg(self,imgurl,vcodeimg):
		f=open(vcodeimg,"wb")
		fp = fetch(imgurl,{},"GetVcode")
		f.write(fp)
		f.close()
		return vcodeimg
	def show_vcode(self,imgfile,error):
		print('filename:',imgfile,error)
		pix = GdkPixbuf.Pixbuf.new_from_file(imgfile)
		fmat = GdkPixbuf.Pixbuf.get_file_info(imgfile)
		print(fmat[0].get_description(),fmat[0].get_extensions(),fmat[0].get_mime_types())
		print(pix)
		#if not self.vcodeimg:
		#self.vcodeimg.clear()
		#self.vcodeimg = Gtk.Image.new_from_pixbuf(pix)
		path = Gtk.TreePath(0)
		#self.liststore.append([pix])
		treeiter = self.liststore.get_iter(path)
		self.liststore.set_value(treeiter, 0, pix)
		#else:
		#	self.vcodeimg = Gtk.Image.set_from_pixbuf(pix)
		#self.vcodeimg.show()
		
		self.spinn.destroy()
예제 #3
0
class LoginDialog(Gtk.Dialog):
    def __init__(self, parent):
        Gtk.Dialog.__init__(self, "Login...", parent, 0)

        self.set_default_size(350, 200)
        self.set_border_width(15)
        grid = Gtk.Grid()
        grid.set_row_spacing(10)
        #grid.set_row_baseline_position(1,Gtk.BaselinePosition.CENTER )
        #labelu = Gtk.Label("User Name:")
        #labelu.set_markup("<span style=\"oblique\">%s</span>")
        #labelp = Gtk.Label("Password:"******"xivhwo2002")
        self.pentry.set_text("mnja12")
        self.pentry.set_visibility(False)
        lbutton = self.add_button("Login...", 11)  #Gtk.Button("Login...")
        lbutton.props.xalign = 0.5
        lbutton.connect("clicked", self.on_click_login)
        offline = Gtk.CheckButton("Offline Mode")
        offline.connect("toggled", self.on_toggle_offline)
        verbose = Gtk.CheckButton("Verbose Mode")
        verbose.connect("toggled", self.on_toggle_verbose)
        box = self.get_content_area()
        box.set_spacing(8)
        #box.add(grid)
        box.add(self.uentry)
        box.add(self.pentry)
        box.add(offline)
        box.add(verbose)
        #grid.add(labelu)
        #grid.attach_next_to(self.uentry,labelu,Gtk.PositionType.RIGHT,13,1)
        #grid.attach(labelp,0, 2, 1, 1)
        #grid.attach_next_to(self.pentry,labelp,Gtk.PositionType.RIGHT,13,1)
        #grid.attach_next_to(lbutton,self.pentry,Gtk.PositionType.BOTTOM,13,1)

        self.infobar = Gtk.InfoBar()
        self.infobar.set_message_type(Gtk.MessageType.ERROR)
        #box.pack_end(self.infobar, False, False, 0)
        #grid.attach_next_to(self.infobar,lbutton,Gtk.PositionType.BOTTOM,13,1)
        box.add(self.infobar)
        info_content = self.infobar.get_content_area()
        self.info_label = Gtk.Label.new("Input username/password to log in..")
        info_content.pack_start(self.info_label, False, False, 0)

        self.infobar.hide()

        self.show_all()

    def on_click_login(self, button):
        self.username = self.uentry.get_text()
        self.password = self.pentry.get_text()
        if not self.username or not self.password:
            self.info_label.set_text("Username or Password is blank.")
            return
        self.info_label.set_text("Going to index")
        logger.info("Username|Password %s %s" % (self.username, self.password))
        self.spinn = SpinnerDialog(self)
        self.spinn.show()
        utils.async_call(auth.index, callback=self.after_goto_index)
        #bdstoken,sign1,sign3,timestamp = auth.index()

        print("click")
        #self.destroy()
    def after_goto_index(self, data, error):
        print(data)
        bdstoken, sign1, sign3, timestamp = data
        if not bdstoken:

            self.info_label.set_text("Geting token")

            #token = auth.get_token()
            utils.async_call(auth.get_token, callback=self.after_get_token)

        else:
            info = "bdstoken %s existing,no need to login again!" % bdstoken
            logger.info(info)
            self.info_label.set_text(info)
            self.spinn.destroy()

    def after_get_token(self, token, error):

        self.token = token
        self.info_label.set_text("Geting public key")
        utils.async_call(auth.get_public_key,
                         self.token,
                         callback=self.after_get_public_key)
        #rsakey,pubkey = auth.get_public_key(token)
    def after_get_public_key(self, data, error):
        rsakey, pubkey = data

        self.info_label.set_text("Loging in now")
        #xml = auth.login(rsakey,pubkey,self.username,self.password,self.token)
        utils.async_call(auth.login,
                         rsakey,
                         pubkey,
                         self.username,
                         self.password,
                         self.token,
                         callback=self.after_login)

    def after_login(self, data, error):
        xml, errdict = data
        if errdict['err_no'] == 257:  #Need verification Code
            codestring = errdict['codeString']
            url = 'https://passport.baidu.com/cgi-bin/genimage?' + codestring

            vd = VcodeDialog(self, url)
            vd.run()
            vf = vd.get_user_input()
            if not vf or len(vf) != 4:
                self.info_label.set_text(
                    "Verification Code missing or incorrect!")
                return
            else:
                vd.destory()
            utils.async_call(auth.relogin,
                             rsakey,
                             pubkey,
                             self.username,
                             self.password,
                             vf,
                             codeString,
                             callback=self.after_login)

        elif errdict['err_no'] == 0:
            self.info_label.set_text("Login Successfully!")
            self.hide()
        self.spinn.destroy()

    def on_toggle_offline(self, button):
        if button.get_active():
            settings.DRY = True
        else:
            settings.DRY = False
        logger.info("Flag DRY toggled to %s" % settings.DRY)

    def on_toggle_verbose(self, button):
        if button.get_active():
            settings.VERBOSE = True
        else:
            settings.VERBOSE = False
        logger.info("Flag VERBOSE toggled to %s" % settings.VERBOSE)
예제 #4
0
class TaskDialog(Gtk.Dialog):
	__metaclass__ = Singleton
	def __init__(self,parent,tokens,save_path):
		Gtk.Dialog.__init__(self, "Download Task", parent, 0)
		self.file_list = []
		#self.downlink = []
		self.tokens = tokens
		
		self.bdstoken,sign1,sign3,timestamp = self.tokens
		#self.file_list = nlist
		#self.remove_list = file_list
		self.current_selection = None
		self.save_path = save_path
		#self.draw_widget(file_list)
		#def draw_widget(self,file_list):
		self.set_default_size(800, 500)
		self.set_border_width(10)


		box = self.get_content_area()

		##							   num,filename,size,status,path,
		#                              0   1       2        3     4    
		self.liststore = Gtk.ListStore(int,str, str, str,str,str)
		#self.liststore.connect("row-changed",self.row_changed)
		self.spinn = SpinnerDialog(self)
		self.spinn.show()
		self.init_view(self.bdstoken)


		#creating the treeview, making it use the filter as a model, and adding the columns
		self.treeview = Gtk.TreeView(model=self.liststore)
		for i, column_title in enumerate(["Num","File", "Size","Status", "Path"]):
						
			renderer = Gtk.CellRendererText()
			column = Gtk.TreeViewColumn(column_title, renderer,text=i)
			self.treeview.append_column(column)

		self.treeview.props.activate_on_single_click = False
		self.treeview.connect("row-activated",self.on_row_double_click)


		self.selection = self.treeview.get_selection()
		self.selection.connect("changed", self.on_tree_selection_changed)
		self.selection.set_mode(Gtk.SelectionMode.MULTIPLE)


		self.buttons = list()
		for act in ["Add Magnet or Ed2k Link File","Select All","Unselect All", "Remove Task"]:
			button = Gtk.Button(act)
			self.buttons.append(button)
			funcname = "on_%s_button_clicked"%act.lower().replace(" ","_")
			
			func = getattr(self, funcname)
			button.connect("clicked", func)


		self.scrollable_treelist = Gtk.ScrolledWindow()
		self.scrollable_treelist.set_vexpand(True)

		box.pack_start(self.scrollable_treelist, True, True, 0)


		for i, button in enumerate(self.buttons):
			#box.pack_start(self.buttons[i], False,False, 0)
			self.add_action_widget(self.buttons[i],i+1)
		self.scrollable_treelist.add(self.treeview)
	

		self.infobar = Gtk.InfoBar()
		self.infobar.set_message_type(Gtk.MessageType.ERROR)
		#box.pack_end(self.infobar, False, False, 0)
		#grid.attach_next_to(self.infobar,lbutton,Gtk.PositionType.BOTTOM,13,1)
		box.add(self.infobar)
		info_content = self.infobar.get_content_area()
		self.info_label = Gtk.Label.new("Add magnet/ed2k file to add offline download task")
		info_content.pack_start(self.info_label, False, False, 0)

		
		self.infobar.hide()
		box.show_all()


	def on_tree_selection_changed(self,*arg):
		self.current_selection = self.selection.get_selected_rows()

	def populate_view(self,*arg):
		listjson,error = arg
		print(listjson)
		if 'task_info' in list(listjson.keys()):
			task_list = listjson['task_info']
		
			file_list = []
			for i,row in enumerate(task_list):
				if int(row['status']) == 0:
					status = "Success"
				else:
					status = "Not Finised"
				nrow = (i,row['task_name'],'0B',status,row['save_path'],row['task_id'])
				file_list.append(nrow)
		
			self.fill_liststore(file_list)
		
		elif 'error_msg' in list(listjson.keys()):
			info =listjson['error_msg']
			logger.info(info)
			self.info_label.set_text(info)
		self.spinn.destroy()
		
	def init_view(self,bdstoken):
		
		utils.async_call(cloudapi.list_task, bdstoken,
				     callback=self.populate_view)

		self.fill_liststore([])

	def fill_liststore(self,file_list):
		if file_list:
			self.liststore.clear()
			for i,filerow  in enumerate(file_list):

				self.liststore.append(list(filerow))


	def on_select_all_button_clicked(self,*arg):
		self.selection.select_all()
	def on_unselect_all_button_clicked(self,*arg):
		self.selection.unselect_all()
	def on_remove_task_button_clicked(self,*arg):
		def is_current_selection_null():
			if not self.current_selection or not self.current_selection[1] :
				dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
		        Gtk.ButtonsType.OK, "Attention.......")
				dialog.format_secondary_text("NO File is selected.!")
				dialog.run()
				dialog.destroy()
				return True
			else:	
				return False
		def after_delete_task(data,error):
			self.info_label.set_text("Deletion is done")
			self.init_view(self.bdstoken)
			self.spinn.destroy()

		if is_current_selection_null(): 
			return
		store,treepaths = self.current_selection
	

		for tpath in treepaths:
			task = ()
			for i in store[tpath]:
				task = task + (i,)
				
			task_id = task[5]
			self.spinn = SpinnerDialog(self)
			self.spinn.show()
			self.info_label.set_text("Deleting task %s "%task[1])
			utils.async_call(cloudapi.delete_task, self.bdstoken,task_id ,
						 callback=after_delete_task)
		#self.liststore.clear()
		#self.fill_liststore(file_list)


	def on_row_double_click(self,*arg):
		pass
	def after_cancel_task(self,*arg):
		
		taskdata,error = arg
		canceljson,task_id,task_name = taskdata
		logger.debug("canceljson: %s "%canceljson)
		info ="Task:%s,id:%s is cancelled."%(task_name,task_id)
		logger.info(info)
		self.info_label.set_text(info)
		self.init_view(self.bdstoken)
		self.spinn.destroy()

	def after_query_task(self,*arg):
		taskdata,error = arg
		taskjson,task_id = taskdata
		#self.init_view(self.bdstoken)
		#taskjson = cloudapi.query_task(task_id)
		logger.debug("taskjson: %s "%taskjson)
		#if task_json:
		file_size = int(taskjson['task_info'][task_id]['file_size'])
		finished_size = int(taskjson['task_info'][task_id]['finished_size'])
		task_name  = taskjson['task_info'][task_id]['task_name']
		logger.debug("file_size: %s "%file_size)
		logger.debug("finished_size: %s "%finished_size)


		if finished_size/file_size < 1 :
			info = "%s : Finished rate is less than 0.6, canceling."%task_name
			logger.info(info)
			self.info_label.set_text(info)
			utils.async_call(cloudapi.cancel_task, self.bdstoken,task_id,task_name,
					 callback=self.after_cancel_task)

		else:
			info = "Task:%s,id:%s is successfully created."%(task_name,task_id)
			logger.info(info)
			self.info_label.set_text(info)
			#self.init_view(self.bdstoken)
			self.spinn.destroy()
			

	def after_add_task(self,*arg):
		taskjson,error = arg
		logger.debug("taskjson: %s "%taskjson)
		if 'task_id' in taskjson.keys():
			task_id = str(taskjson['task_id'])
			utils.async_call(cloudapi.query_task, self.bdstoken,task_id,
				     callback=self.after_query_task)

		else:
			error = taskjson['error_msg']
			logger.info(error)
			self.info_label.set_text(error)
			#self.init_view(self.bdstoken)
			self.spinn.destroy()

		#self.spinn.destroy()

	def on_add_magnet_or_ed2k_link_file_button_clicked(self,*arg):
		dialog = Gtk.FileChooserDialog("Please choose a file", self,
			Gtk.FileChooserAction.OPEN,
			(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
			 Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

		response = dialog.run()
		if response == Gtk.ResponseType.OK:
			#linkfile = dialog.get_file().read()
			filename = dialog.get_filename()
			
			print("Open clicked")
			print("File selected: " + dialog.get_filename())
		elif response == Gtk.ResponseType.CANCEL:
			return
		
		dialog.destroy()
		
		link_list = open(filename).read()
		task_list = []
		invalid_list = []
		for line in link_list.split("\n"):
			line = line.strip()
			if line and ( line.startswith("magnet:?xt=urn") or \
				 line.startswith("ed2k://") ):
				task_list.append(line)
				
			elif line:
				invalid_list.append(line)
		if invalid_list:
				dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
						Gtk.ButtonsType.OK, "Attention")
				dialog.format_secondary_text(
						"Only magnet or ed2k protocal is support! Invalid lines :%s"%str(invalid_list))
				response = dialog.run()
				dialog.destroy()
				return 
		print(self.save_path)
		
		maglist = [ i['source_url'] for i in self.task_list   if "magnet:?xt=urn:" in i['source_url'] ]
		logger.debug("maglist: %s "%str(maglist))
		
		for i,l in enumerate(task_list):
			mag = re.search('(&.*$)',l).group(1)
			task_name = dict(urllib.parse.parse_qsl(mag))['dn']
			txt = "%s out of %s | %s is running."%(str(i),len(task_list),str(task_name))
			logger.info(txt)
			self.info_label.set_text(txt)
			maglink = re.search("(magnet[^&]*)",l).group(1)
			logger.debug("maglink: %s "%maglink)
			self.spinn = SpinnerDialog(self)
			self.spinn.show()
			if maglink not in maglist:
				
				self.info_label.set_text("Adding task: %s "%task_name)
				taskjson = cloudapi.add_task(self.bdstoken, l,self.save_path,self)
				self.init_view(self.bdstoken)
				self.spinn.destroy()

				#taskjson = cloudapi.add_task(l,self.save_path)
				logger.debug("taskjson: %s "%taskjson)
				if 'task_id' in taskjson.keys():
					self.spinn = SpinnerDialog(self)
					self.spinn.show()
					self.info_label.set_text("Querying task: %s "%task_name)
					task_id = str(taskjson['task_id'])
					utils.async_call(cloudapi.query_task, self.bdstoken,task_id,
							 callback=self.after_query_task)
					self.spinn.destroy()
				else:
					error = taskjson['error_msg']
					logger.info(error)
					self.info_label.set_text(error)
					#self.spinn.destroy()
				
			else:
				info = "Already existed,pass"
				logger.info(info)
				self.info_label.set_text(info)
			
				self.spinn.destroy()
예제 #5
0
class LoginDialog(Gtk.Dialog):

	def __init__(self, parent):
		Gtk.Dialog.__init__(self, "Login...", parent, 0)

		self.set_default_size(350, 200)
		self.set_border_width(15)
		grid = Gtk.Grid()
		grid.set_row_spacing(10)
		#grid.set_row_baseline_position(1,Gtk.BaselinePosition.CENTER )
		#labelu = Gtk.Label("User Name:")
		#labelu.set_markup("<span style=\"oblique\">%s</span>")
		#labelp = Gtk.Label("Password:"******"xivhwo2002")
		self.pentry.set_text("mnja12")
		self.pentry.set_visibility(False)
		lbutton = self.add_button("Login...",11) #Gtk.Button("Login...")
		lbutton.props.xalign  = 0.5
		lbutton.connect("clicked",self.on_click_login)
		offline = Gtk.CheckButton("Offline Mode")
		offline.connect("toggled",self.on_toggle_offline)
		verbose = Gtk.CheckButton("Verbose Mode")
		verbose.connect("toggled",self.on_toggle_verbose)
		box = self.get_content_area()
		box.set_spacing(8)
		#box.add(grid)
		box.add(self.uentry)
		box.add(self.pentry)
		box.add(offline)
		box.add(verbose)
		#grid.add(labelu)
		#grid.attach_next_to(self.uentry,labelu,Gtk.PositionType.RIGHT,13,1)
		#grid.attach(labelp,0, 2, 1, 1)
		#grid.attach_next_to(self.pentry,labelp,Gtk.PositionType.RIGHT,13,1)
		#grid.attach_next_to(lbutton,self.pentry,Gtk.PositionType.BOTTOM,13,1)

		self.infobar = Gtk.InfoBar()
		self.infobar.set_message_type(Gtk.MessageType.ERROR)
		#box.pack_end(self.infobar, False, False, 0)
		#grid.attach_next_to(self.infobar,lbutton,Gtk.PositionType.BOTTOM,13,1)
		box.add(self.infobar)
		info_content = self.infobar.get_content_area()
		self.info_label = Gtk.Label.new("Input username/password to log in..")
		info_content.pack_start(self.info_label, False, False, 0)

		
		self.infobar.hide()

		self.show_all()

	def on_click_login(self,button):
		self.username = self.uentry.get_text()
		self.password = self.pentry.get_text()
		if not self.username or not self.password:
			self.info_label.set_text("Username or Password is blank.")
			return
		self.info_label.set_text("Going to index")
		logger.info("Username|Password %s %s"%(self.username,self.password))
		self.spinn = SpinnerDialog(self)
		self.spinn.show()
		utils.async_call(auth.index,
							 callback=self.after_goto_index)
		#bdstoken,sign1,sign3,timestamp = auth.index()


		print("click")
		#self.destroy()
	def after_goto_index(self,data,error):
		print(data)
		bdstoken,sign1,sign3,timestamp = data
		if not bdstoken:

			self.info_label.set_text("Geting token")
			
			#token = auth.get_token()
			utils.async_call(auth.get_token, 
							 callback=self.after_get_token)

		else:
			info = "bdstoken %s existing,no need to login again!"%bdstoken
			logger.info(info)
			self.info_label.set_text(info)
			self.spinn.destroy()

	def after_get_token(self,token,error):

			self.token = token
			self.info_label.set_text("Geting public key")
			utils.async_call(auth.get_public_key,self.token,
							 callback=self.after_get_public_key)
			#rsakey,pubkey = auth.get_public_key(token)
	def after_get_public_key(self,data,error):
		rsakey,pubkey = data
		
		self.info_label.set_text("Loging in now")
		#xml = auth.login(rsakey,pubkey,self.username,self.password,self.token)
		utils.async_call(auth.login,rsakey,pubkey,self.username,self.password,self.token,
							 callback=self.after_login)
	def after_login(self,data,error):
		xml,errdict = data
		if errdict['err_no']  == 257 : #Need verification Code
			codestring = errdict['codeString'] 
			url = 'https://passport.baidu.com/cgi-bin/genimage?' + codestring
			
			vd = VcodeDialog(self,url)
			vd.run()
			vf = vd.get_user_input()
			if not vf or len(vf) != 4:
				self.info_label.set_text("Verification Code missing or incorrect!")
				return
			else:
				vd.destory()
			utils.async_call(auth.relogin,rsakey,pubkey,self.username,self.password,vf,codeString,
							 callback=self.after_login)

		elif errdict['err_no']  == 0: 
			self.info_label.set_text("Login Successfully!")
			self.hide()
		self.spinn.destroy()

	def on_toggle_offline(self,button):
		if button.get_active():
			settings.DRY = True
		else:
			settings.DRY = False
		logger.info("Flag DRY toggled to %s"%settings.DRY)
	def on_toggle_verbose(self,button):
		if button.get_active():
			settings.VERBOSE = True
		else:
			settings.VERBOSE = False
		logger.info("Flag VERBOSE toggled to %s"%settings.VERBOSE)